文件名称:Authorization in ASP.Net MVC using XML Configuration.
文件大小:236KB
文件格式:ZIP
更新时间:2012-07-23 05:14:37
Authorization ASP.Net MVC XML
Doing authorization in a clean way is always tricky, You want a delicate balance between an extreme abstraction and something like embedding roles in-side your compiled code, I have always preferred simple abstraction either using roles and their corresponding mappings in the database or using simple xml file to store action to role mappings. Asp.net MVC comes with built in Authorization filter attribute that you can use on your Controller and Action to define the role that can access corresponding Controller or Action. This approach will work fine for small application where you have predefined action to role mappings, but when you have bigger application where developers are not going to define role mappings and mappings might change frequently then maintenance of hard quoted roles might become nightmare. I have created simple application to demonstrate how you can xml based configuration to apply authorization in MVC application. Following are four major pieces of the application. ConfigurationSectionHandler for defining XML Configuration for Controller and Action to role mapping. IMVCAuthorizer Interface and implementation MCVXMLAuthorizer. HttpModule which plugs into AuthorizeRequest event to validate if user are authorized to access Controller and Action. Sample MVC application to test XMLAuthorizer.
【文件预览】:
MVCAuthorizationExperiment
----MVCAuthorizationExperiment.UI()
--------MVCAuthorizationExperiment.UI.csproj(7KB)
--------Scripts()
--------Global.asax(3KB)
--------bin()
--------Web.config(11KB)
--------Authorization.config(696B)
--------obj()
--------Properties()
--------App_Data()
--------Default.aspx(282B)
--------Views()
--------Default.aspx.cs(455B)
--------MVCAuthorizationExperiment.UI.csproj.user(1KB)
--------Content()
--------Models()
--------Controllers()
----MCVAuthorization()
--------bin()
--------AuthorizationInfo.cs(2KB)
--------ActionAuthorizationInfo.cs(335B)
--------ControllerAuthorizationInfoCollection.cs(3KB)
--------obj()
--------MVCAuthorization.csproj(4KB)
--------Properties()
--------AuthorizationMappingSection.cs(2KB)
--------MCVXMLAuthorizer.cs(2KB)
--------IMVCAuthorizer.cs(1KB)
--------AuthorizationMappingModule.cs(3KB)
--------ControllerAuthorizationInfo.cs(1KB)
----MVCAuthorizationExperiment.sln(1KB)