簡體   English   中英

保護ASP.NET MVC4中的視圖:表單身份驗證

[英]Secure the View in ASP.NET MVC4 : Forms Authentification

我想在視圖中為每個用戶呈現不同的內容。 Asp.net mbc4中執行此操作的正確方法是什么?

我正在尋找類似於在Spring security中保護視圖的內容:

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

在您看來,您應該能夠對User屬性進行檢查:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM