14

In my web.config file I have all the references to elmah that I need in order to have elmah running. Except this part of the code:

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

Either ReSharper or Visual Studio is giving me the error:

Location element is unused: no project found at elmah.axd path:Path to web project\elmah.axd not found

I installed the elmah package from NuGet and I have the dll saved and when I go to the root of my site and type root/elmah.axd I am able to access the elmah logs; however, I need to restrict the access of these logs to admins.

I have two users: Admin and User I want only those with Admin role to access the elmah logs.

Am I missing a piece to this puzzle?

jrummell
  • 42,637
  • 17
  • 112
  • 171
Robert
  • 4,306
  • 11
  • 45
  • 95
  • 1
    Where are you getting the error? – MikeSmithDev Mar 05 '13 at 19:26
  • When I have my web.config file open the Location tag is greyed out and when I hover over it I get the error – Robert Mar 05 '13 at 19:47
  • How did you install Elmah? If you run `Install-Package Elmah` from package manager console, all you have to do is uncomment out those authorization lines in the web.config for it to work. – MikeSmithDev Mar 05 '13 at 20:00
  • That is how I installed it. I ran Install-Package Elmah from NuGet. It gave me the lines for authorization however I am not using the default MVC authorization tools. We have to do authorization through an external source for our app so I need to allow only admins on the site access to the elmah logs – Robert Mar 05 '13 at 20:02
  • Can you debug `User.IsInRole("admin")` for your user and make sure you're actually set up in that role? – Mathew Thompson Mar 05 '13 at 20:03
  • @Robert Hm. Are you saying the error only happens when you comment out the authorization lines? It doesn't seem the two should be related. – MikeSmithDev Mar 05 '13 at 20:18
  • No I have my webconfig open and everything is uncommented. Either Visual Studio or resharper is giving me the above error when I hover over the element – Robert Mar 05 '13 at 20:34
  • It's ReSharper, you can ignore it. ReSharper is amazing, but it occasionally misreports unused code. – jrummell Mar 05 '13 at 20:55

1 Answers1

19

There is nothing wrong... it's just reSharper being a bit silly. Because it can't find a physical file with that name, it thinks it doesn't exist and gives you that error you are seeing.

You can ignore it by using a ReSharper disable comment like so:

<!-- ReSharper disable WebConfig.RedundantLocationTag -->
<!-- ReSharper disable WebConfig.WebConfigPathWarning -->
<location path="elmah.axd">
<!-- ReSharper restore WebConfig.WebConfigPathWarning -->
  <system.web>
    <authorization>
      <allow roles="admin" />
      <deny users="*" />
    </authorization>
  </system.web>
</location>
<!-- ReSharper restore WebConfig.RedundantLocationTag -->

But it looks ugly ;-)

Charlino
  • 15,802
  • 3
  • 58
  • 74
  • I think you can safely ignore this. The axd should exist at runtime. The resharper comment only disables the warning. It doesn't prevent the ui dimming over that section. It is a bug I suppose in resharper, but it doesn't bother me. – Bon Mar 27 '15 at 08:59