Asp.net Global.asax问题

编程入门 行业动态 更新时间:2024-10-28 02:26:31
本文介绍了Asp Global.asax问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

wed config

wed config

<location path="~/elmah.axd"> <system.web> <authorization> <allow roles="Administrator"/> <deny users="*"/> </authorization> </system.web> </location> </configuration>

和我的appl_benRequest

and my appl_benRequest

protected void Application_BeginRequest() { if (Request.Url.AbsolutePath.ToLowerInvariant().Contains("elmah.axd")) { // Check if user can see elmah and handle unauthorised users (return 401/redirect to login page/etc...) } how to find login person roleid here plz help me out ...Thanks a lot in advance }

推荐答案

有很多方法可能对您有所帮助。 查看System.Web.Security命名空间 //查看当前用户是否处于管理员角色 User.IsInRole(管理员) //给出当前用户所有角色的列表 Roles.GetRolesForUser ( User.Identity.Name) //给出管理员角色中所有用户的列表 Roles.GetUsersInRole(Administrator) 如果我需要检查用户是否处于管理员角色,我会这样做 if(User.IsInRole(Administrator) ) { //代码 } There are a number of methods that may be helpful to you. Check out the System.Web.Security namespace //find out if the current user is in the administrators role User.IsInRole("Administrator") //gives a list of all roles the current user is in Roles.GetRolesForUser(User.Identity.Name) //gives list of all users in administrators role Roles.GetUsersInRole("Administrator") If i needed to check if a user was in the Administrator role, i would do this if (User.IsInRole("Administrator")) { //code }

对不起,我无法弄清楚如何添加评论中的代码,所以我只是提交另一个答案。 Sorry, i cannot figure out how to add code in a comment, so i am just submitting another answer. A couple of things I noticed. You are doing this in your web.cofig: <pre> <location path="~/elmah.axd"> <system.web> <authorization> <allow roles="Administrator"/> <deny users="*"/> </authorization> </system.web> </location> </pre> Now, if that is setup correctly, when someone not in the administrator group tries to view the elmah page, it will give them an access denied message. There is no reason to check again in the global.asax. Try changing: <pre> <location path="~/elmah.axd"> </pre> To: <pre> <location path="elmah.axd"> </pre> Even if you MUST check in the global.asax for some reason, the place would not be application_BeginRequest Here is a link to an article that may help you find the right method to use in the Global.asax stackoverflow/questions/3072768/net-application-beginrequest-how-to-get-user-reference

更多推荐

Asp.net Global.asax问题

本文发布于:2023-11-04 10:04:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:net   Asp   asax   Global

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!