如何使用Windows集成安全性在ASP.Net MVC 4上保护Elmah:Elmah忽略了我的设置

Twi*_*ted 16 .net asp.net security asp.net-mvc elmah

我已将elmah添加到asp.net mvc 4应用程序中.日志记录正在运行,现在我正在尝试配置安全性,但elmah没有获取设置,所有用户仍然可以看到日志.

这是一个内部网应用程序,因此我们使用windows集成secuirty.我正在尝试限制访问权限,以便只有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>
Run Code Online (Sandbox Code Playgroud)

我还尝试通过设置我的autorisation配置以拒绝所有人来完全锁定

<authorization>
<deny users="*" />
</authorization>
Run Code Online (Sandbox Code Playgroud)

并且

<authorization>
<deny users="?" />
</authorization>
Run Code Online (Sandbox Code Playgroud)

日志对所有人开放.

我怀疑问题可能与位置有关.我没有改变elmah的位置.它是从默认位置访问的(http:// server/myapp/elmah)

Jac*_*hes 29

如果您使用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>
Run Code Online (Sandbox Code Playgroud)

感兴趣的关键是elmah.mvc.requiresAuthentication用户需要登录哪些开关.elmah.mvc.allowedRoles它指定用户必须在哪个角色.

您可以从nuget安装Elmah.Mvc.