dynamically allow roles to a page or folder

孤街醉人 提交于 2019-12-11 21:13:14

问题


I am using asp.net webforms. I use a web.config to define what roles can access pages and folders. like this

   <system.web>
     <authorization>
       <allow roles="Admin" />
       <deny users="*" />
     </authorization>
   </system.web>

how can I do this dynamically? so without deploying I could add a role, like 'Developer'

Is there a way I could read these from a database? thanks


回答1:


Not sure what exactly are you asking here...

The authorization sighted by you is known as URL Authorization and provided by in-build ASP.NET module. This implementation uses the context associated IPrincipal (HttpContext.User) to see the authenticated user is member of configured role. So if you want to have your own arbitrary roles (instead of windows roles), you can provide your own IPrincipal implementation that would retrieve the assigned roles for the current user from the data-base (or any other source that you want to use). However, the authorization information will still remain in the configuration file.

In case, you want to move the authorization information (who can access what) then you can implement your own authorization module. The module can read this information from the database and enforce the access security the way you wanted.



来源:https://stackoverflow.com/questions/8008752/dynamically-allow-roles-to-a-page-or-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!