2013-11-22 83 views
1

我使用VS2012創建了MVC3 Intranet應用程序。它使用Windows身份驗證。它在我的本地IIS上運行。 IIS有匿名&已啓用Windows身份驗證。MVC3應用程序(Windows身份驗證)啓用匿名訪問

只要我運行該應用程序,就會出現登錄彈出窗口。

的HomeController:

public ActionResult Index() 
{ 
    ViewBag.Message = "Welcome to ASP.NET MVC!"; 

    return View(); 
} 

的TestController:

[Authorize] 
public ActionResult Index() 
{ 
    ViewBag.Message = "Welcome to ASP.NET MVC!"; 

    return View(); 
} 

我想知道怎麼做才能做的是​​指定的[授權]屬性,只有當有用戶身份驗證...在換言之,當用戶進入該網站(家庭)時,不需要登錄。當他們導航到TestController時,他們必須登錄。

回答

0

明確指定這樣的:

[AllowAnonymous] 
public ActionResult Index() 
{ 
    ViewBag.Message = "Welcome to ASP.NET MVC!"; 

    return View(); 
} 
0

的授權屬性可以放在類級或行動水平。如果您將其放置到課程級別,則每個操作都需要您登錄。如果您將其放置在操作級別上,則只有該特定操作需要用戶身份驗證。

[Authorize] 
public class CustomerServiceController 
{ 
    .... 
} 

public class AccountController 
{ 
    [AllowAnonymous] 
    public ActionResult Index() 
    { 
     .... 
    } 

    [Authorize] 
    public ActionResult Accounts() 
    { 
     .... 
    } 
} 
相關問題