ASP.Net MVC:elmah.axd 将仅供管理员角色访问

ASP.Net MVC: elmah.axd will be accessible for admin role only

我读了这篇文章来实现 elmah http://www.c-sharpcorner.com/UploadFile/858292/exception-logging-in-mvc-using-elmah/

但我希望只有具有管理员角色的授权人员才能看到 elmah.axd 文件。我该怎么做?指导我。

我找到了一种使用管理员角色附加 elmah.axd 文件的方法。这是代码

https://blog.elmah.io/elmah-tutorial/

<location path="elmah.axd">
    <system.web>
        <httpHandlers>
            <add verb="POST,GET,HEAD"
                 path="elmah.axd"
                 type="Elmah.ErrorLogPageFactory, Elmah" />
        </httpHandlers>
        <authorization>
            <allow roles="admin" />
            <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>

告诉我以上方法是保护管理员角色 elmah.axd 文件的唯一方法。

来自这个linkhttps://blog.elmah.io/elmah-security-and-allowremoteaccess-explained/

我找到了这个

<appSettings>
    <add key="elmah.mvc.requiresAuthentication" value="true" />
    <add key="elmah.mvc.allowedRoles" value="Admin" />
    <add key="elmah.mvc.allowedUsers" value="Thomas" />
</appSettings>

如果我在 web.config 文件中添加以上条目,则除管理员角色外,没有授权用户无法访问 elmah.axd 文件......我有疑问。请有人指导我。

据我从文档中了解到,第一个示例是 ASP.NET 的通用解决方案。这对 MVC 有一些问题,特别是 MVC 的 HandleErrorAttribute 以及获取自定义错误。

第二个示例是针对 Elmah.MVC 的,这是一个专门针对 ASP.NET MVC 的包。这是在使用 MVC 框架时设置 Elmah 的推荐方式。

<appSettings>
    <add key="elmah.mvc.requiresAuthentication" value="true" />
    <add key="elmah.mvc.allowedRoles" value="Admin" />
    <add key="elmah.mvc.allowedUsers" value="Thomas" />
</appSettings>

What about ASP.NET MVC?

ELMAH were originally created for ASP.NET. Different features available in ASP.NET MVC have been causing a lot of head-scratching since introduced back in 2007. Some of you may have struggled with MVC's HandleErrorAttribute as well as getting custom errors and ELMAH working at the same time. In 2011, Alexander Beletsky created the Elmah.MVC package to help MVC developers using ELMAH. We highly recommend MVC projects to use this package, since it removes a lot of the frustrations that people are having with MVC and ELMAH.

https://blog.elmah.io/elmah-security-and-allowremoteaccess-explained/