myhn/Apps/Website/AuthenticatedTagHelper.cs
2021-01-08 16:26:19 +01:00

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");
}
}
}