Stuck creating a “security trimmed” html.ActionLink extension method

后端 未结 3 868
难免孤独
难免孤独 2021-01-06 08:08

I\'m trying to create an Extension Method for MVC\'s htmlHelper. The purpose is to enable or disable an ActionLink based on the AuthorizeAttribute set on the controller/acti

3条回答
  •  旧巷少年郎
    2021-01-06 08:40

    Your ViewPage has a reference to the view context, so you could make it an extension method on that instead.

    Then you can just say if Request.IsAuthenticated or Request.User.IsInRole(...)

    usage would be like <%= this.SecurityLink(text, demandRole, controller, action, values) %>

提交回复
热议问题