开发者

ASP.Net IIS location path authorization issue

开发者 https://www.devze.com 2023-03-03 11:22 出处:网络
I have a website that uses forms authentication with an image on the master page that will not display when published to the host web server, however it will display when hosted on my local machine.Th

I have a website that uses forms authentication with an image on the master page that will not display when published to the host web server, however it will display when hosted on my local machine. The site is using ASP.Net web forms on the 4.0 framework and both environments are using IIS 7. Does anyone know why this will not work when published out to the server? If I go to http://serverwebsiteaddr/images/logo_myworkplace.jpg on the server it redirects me to the login page, but the image correctly displays if I go to the analogous url on my dev box http://devmachinenameaddr/images/logo_myworkplace.jpg

Here is my configuration file:

<system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/login.aspx" name=".ASPXFORMSAUTH" slidingExpiration="true"/>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
</system.web>

<location path="images/logo_myworkplace.jpg"开发者_如何学运维>
<system.web>
  <authorization>
    <allow users ="*" />
  </authorization>
</system.web>

Server Configuration: IIS 7.5, Windows Server 2008 R2, Dev Box: IIS 7.5, Windows 7 Enterprise


Add a web.config file to your images directory and put the following in it. Essentially you want to turn off authentication for that directory. This is untested, btw. Not sure if it will work.

<configuration>
  <system.web>
    <authentication mode="Forms" />
  </system.web>
</configuration>


You might have a passthrough setting on IIS that routes all files through the .NET HttpHandler. This is useful for protecting members only content for everything in a directory. If the HttpHandler is enabled for JPG files, it will first run the authentication rules from the web.config before delivering the file. Your local box may not have that set up.


While the top folder has specific authorization to protect its files, I could set another authorization for its subfolder, with an inner web.config. So I can see .aspx pages on this subfolder without problem.

<?xml version="1.0"?>
<configuration>
    <system.web>
      <identity impersonate="true" />
      <authorization>
        <allow users="*" />
        <deny users="*" />
      </authorization>
    </system.web>
</configuration>


A shot in the dark:

Could it be that the images subfolder is mapped to another app pool that is not in integrated mode ?

0

精彩评论

暂无评论...
验证码 换一张
取 消