我已将 elmah 添加到 asp.net mvc 4 应用程序中。
日志记录正在运行,现在我正在尝试配置安全性,但 elmah 没有选择设置,并且所有用户都可以看到日志。
这是一个 Intranet 应用程序,因此我们使用的是 Windows 集成安全性。我正在尝试限制访问,以便只有 domain\log_readers 广告组的成员才能读取日志。
我在这里阅读了设置指南:http://code.google.com/p/elmah/wiki/SecuringErrorLogPages并且我还阅读了有关 SO 和其他表格的几篇文章,这导致我添加了 roleManager 和 WindowsRoleProvider 配置,但都无济于事。
这是我的 web.config 的 elmah 部分:
<elmah>
<!--
See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for
more information on remote access and securing ELMAH.
-->
<security allowRemoteAccess="true" />
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/Logs" />
</elmah>
<location path="elmah.axd" inheritInChildApplications="false">
<system.web>
<authentication mode="Windows" />
<roleManager defaultProvider="WindowsProvider"
enabled="true" cacheRolesInCookie="false">
<providers>
<add
name="WindowsProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<!--
See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for
more information on using ASP.NET authorization securing ELMAH.
-->
<authorization>
<allow roles="domain\log_readers"/>
<deny users="*" />
</authorization>
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>
我还尝试通过将我的授权配置设置为拒绝所有人来完全锁定
<authorization>
<deny users="*" />
</authorization>
并且
<authorization>
<deny users="?" />
</authorization>
日志对所有人开放。
我怀疑问题可能出在位置上。我没有对 elmah 位置进行任何更改。它是从默认位置访问的 ( http://server/myapp/elmah )
最佳答案
如果您使用 Elmah.Mvc,它们具有非常细粒度的安全设置。例如,您可以轻松确保 elmah 页面仅对 Admin 组中的登录用户可用。
Elmah.Mvc 在 <appSettings>
中支持以下项目
<appSettings>
<!-- ELMAH configuration. Admin page only available for logged in users in
the Admin role. -->
<add key="elmah.mvc.disableHandler" value="false" />
<add key="elmah.mvc.disableHandleErrorFilter" value="false" />
<add key="elmah.mvc.requiresAuthentication" value="true" />
<add key="elmah.mvc.allowedRoles" value="Admin" />
<add key="elmah.mvc.route" value="elmah" />
</appSettings>
感兴趣的键是
elmah.mvc.requiresAuthentication
它打开需要登录的用户。和 elmah.mvc.allowedRoles
它指定用户必须处于哪个角色。您可以从 nuget 安装 Elmah.Mvc。
关于asp.net - 如何使用 Windows 集成安全 : Elmah ignores my settings 在 ASP.Net MVC 4 上保护 Elmah,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13703763/