How to provide only Access for ELMAH.axd for Administrator login in web

假装没事ソ 提交于 2019-11-30 20:18:48

If you're using Roles you can add this to your web.config:

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

If you're not using roles you will have to specify each user you want to give access to:

<location path="~/elmah.axd">
    <system.web>
        <authorization>
            <allow users="user1, user2, user3" />
            <deny users="*" />
        </authorization>
    </system.web>
</location>

Update:

As you aren't using any of the built in authentication/authorisation and you don't have control of the elmah page you're going to have to handle the 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...)
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!