【问题标题】:Secure the View in ASP.NET MVC4 : Forms Authentification保护 ASP.NET MVC 4 中的视图:表单身份验证
【发布时间】:2014-05-19 10:17:58
【问题描述】:

我想在视图中为每个用户呈现不同的内容。在 Asp.net mbc4 中这样做的正确方法是什么。

我正在寻找类似于在 Spring 安全中保护视图的东西:

<sec:authorize access="hasRole('supervisor')">

    This content will only be visible to users who have
    the "supervisor" authority in their list of <tt>GrantedAuthority</tt>s.

</sec:authorize>

到目前为止,我只能保护对控制器的访问:

    [Authorize(Roles = "supervisor")]
    public ActionResult Index()
    {
        return View("");
    }

【问题讨论】:

    标签: asp.net asp.net-mvc security forms-authentication


    【解决方案1】:

    在您看来,您应该能够检查您的 User 属性:

    @if(User.IsInRole("supervisor"))
    {
    //Markup here...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      • 2014-06-06
      相关资源
      最近更新 更多