我已经创建了应用程序并实现了 ELMAH 日志记录。在我的网站中,存在三种类型的用户。
Admin: 一切都可以(查看 elmah.axd 的权利)
User: 可以拥有自己的权限(无法查看 elamh.axd)
Guest:只能查看(无法查看elamh.axd)
上述用户将被存储在数据库中。
问题:-现在我如何管理用户和来宾查看 ELMAH.axd 日志文件的保护级别?
如果您正在使用Roles你可以将其添加到你的 web.config 中:
<location path="~/elmah.axd">
<system.web>
<authorization>
<allow roles="Admin" />
<deny users="*" />
</authorization>
</system.web>
</location>
如果您不使用角色,则必须指定要授予访问权限的每个用户:
<location path="~/elmah.axd">
<system.web>
<authorization>
<allow users="user1, user2, user3" />
<deny users="*" />
</authorization>
</system.web>
</location>
Update:
由于您没有使用任何内置的身份验证/授权,并且您无法控制 elmah 页面,因此您将不得不处理BeginRequest()
event:
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...)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)