31 lines
757 B
C#
31 lines
757 B
C#
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
|
using Microsoft.AspNetCore.Razor.TagHelpers;
|
|
|
|
namespace Website
|
|
{
|
|
[HtmlTargetElement(Attributes = "is-authenticated")]
|
|
public class AuthenticatedTagHelper : TagHelper
|
|
{
|
|
public AuthenticatedTagHelper()
|
|
{
|
|
|
|
}
|
|
|
|
[ViewContext]
|
|
public ViewContext ViewContext { get; set; }
|
|
|
|
public override void Process(TagHelperContext context, TagHelperOutput output)
|
|
{
|
|
if (!ViewContext.HttpContext.User.Identity.IsAuthenticated)
|
|
{
|
|
output.SuppressOutput();
|
|
}
|
|
else
|
|
{
|
|
output.Attributes.Remove(new TagHelperAttribute("is-authenticated"));
|
|
}
|
|
// output.Attributes.SetAttribute("class", "btn");
|
|
}
|
|
}
|
|
} |