我開始將ASP.NET Webforms應用程序遷移到ASP.NET MVC 3.應用程序有一個公共區域,所有用戶都可以訪問該區域(匿名用戶)和幾個區域,這些區域只能由具有特定角色的經過身份驗證的用戶訪問。將授權邏輯從ASP.NET Webforms遷移到ASP.NET MVC3
該項目的WebForms組織像這樣:
Root folder -> contains all public pages
|
--- Private subfolder -> contains a few pages for ALL authenticated users
|
--- Customers subfolder -> contains pages for users in role "Customer"
--- Suppliers subfolder -> contains pages for users in role "Supplier"
--- Internals subfolder -> contains pages for users in role "Internal"
|
--- Admins subfolder -> contains pages for users in role "Admin"
etc.
目前的授權是由web.config
文件,這是在不同的子文件夾管理。例如,該子文件夾Customers
包含以下web.config
:需要
<configuration>
<system.web>
<authorization>
<allow roles="Customer" />
<deny users="*" />
</authorization>
</system.web>
</configuration>
在ASP.NET Web表單沒有更多的配置即可。此授權適用於Customers
子文件夾中的所有頁面。
將此結構遷移到ASP.NET MVC 3的最佳方式是什麼?或更具體地說:
- 做這樣的
web.config
具有授權設置的文件仍然在MVC文件夾的基礎上工作? - 如果沒有,是否有另一種方法來將授權要求應用於文件夾中的所有頁面?
- 我還可以組織不同區域在不同的文件夾,特別是可以把我個人
Controllers
,Views
,下的每個文件夾Customers
,Suppliers
等Models
子文件夾,以保持所有的邏輯和標記併攏?
感謝您的反饋!
你可以看看http://prodinner.codeplex.com樣品,以瞭解如何在MVC使用授權 – Omu 2011-05-08 18:27:16