I came from asp.net 2.0 webforms; where i just define my menu in Web.sitemap with all the trimming taken care off.
Is there any equivalent feature in asp.net-core-mvc for this seemingly easy task ?
I came from asp.net 2.0 webforms; where i just define my menu in Web.sitemap with all the trimming taken care off.
Is there any equivalent feature in asp.net-core-mvc for this seemingly easy task ?
You can create a custom TagHelper for it, inside this tag helper you can check whether user is in apporperiate role or not:
public class SecurityTrimmingTagHelper : TagHelper
{
[ViewContext]
public ViewContext Context { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = null;
if (!Context.HttpContext.User.Identity.IsAuthenticated)
{
output.SuppressOutput();
}
if (Context.HttpContext.User.IsInRole("Admin"))
{
return;
}
output.SuppressOutput();
}
}