Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have created application and implemented ELMAH logging. In my site there are three types of users.

  • Admin : can everything (rights to view elamh.axd)
  • User : can have own rights (can't view elamh.axd)
  • Guest : only view (can't view elamh.axd)
  • The above user will be stored in Database.

    Probelm:- Now how could i manage protection level for User and Guest to view ELMAH.axd log file?

    like image 678
    imdadhusen Avatar asked Aug 10 '11 02:08

    imdadhusen


    1 Answers

    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...)
        }
    }
    
    like image 134
    Adam Flanagan Avatar answered Oct 08 '22 04:10

    Adam Flanagan



    Donate For Us

    If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!