2011-02-06 70 views

回答

0

真的有你在看兩個問題:

  • 認證,通過內置迎刃而解 - 在成員資格提供或開放身份驗證或LDAP或什麼的。標準ASP.NET支持有效。
  • 授權,有趣的部分。根據進入的內容可能無關緊要,或者它可能會非常細膩。默認是騎在ASP.NET RoleProviders的欄杆上。

在一天結束時,ASP.NET MVC2身份驗證與身份驗證ASP.NET沒有多大區別。標準票價適用。

0

我不認爲有什麼特別的。它應該「只是工作」。在fcat中的MVC默認模板爲你創建了一堆鍋爐代碼。

0

它的工作方式與ASP.NET WebForms幾乎相同,但是通過使用屬性裝飾操作或控制器來控制對網站不同部分的訪問。

例子:

public class HomeController 
{ 
     // Does not require any authentication 
     public ActionResult Index(int id) 
     { 
      return View(); 
     } 


    // Requires login, and that the logged in user is in the "Users"-Role 
    [Authorize(Roles="Users")] 
    public ActionResult SemiSecret(int id) 
    { 
      return View(); 
    } 

    // Same as above, but requires user to be in "Admin" Role 
    [Authorize(Roles="Admin")] 
    public ActionResult TopSecret(int id) 
    { 
      return View(); 
    } 
} 

一個控制器上:

// All actions in this controller requires users to log in and be in "Admin" role 
[Authorize(Roles="Admin")] 
public class AdminController 
{ 
     // Controller code goes here ... 
} 

您還可以通過使用[Authorize(Users="UserName")]

希望這有助於限制對用戶級!