2012-03-28 31 views
0

我们有一个不显示图像的Web应用程序上显示出来,CSS,除非用户已登录。 我们正在使用窗体身份验证位置路径设置不登录页面

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOn" timeout="2880" cookieless="UseCookies" /> 
    </authentication> 

现在我们在web.config文件中专门使用这个配置下的部分来授予匿名用户访问“content”文件夹的权限。

<location path="Content"> 
    <system.web> 
    <authorization> 
    <allow users="?"/> 
    </authorization> 
    </system.web> 
    </location>  

但仍然没有图像,没有css显示,除非登录。如果我们试图直接访问图像需要我们登录页面。 有没有人知道发生了什么?

回答

0

如果您尝试在IIS 7.5中显示图像,您是否注意到有两种方法(first is here)使用<location>标记,它对我来说更令人困惑。

无论如何,如果您使用IIS 7.5,这可能会有帮助。

下面的示例适用于以.NET 4.5为目标的MVC应用程序,该应用程序将显示一个组的文件夹并将其隐藏到另一个组中。

<configuration> 
    <system.web> 
    <!-- allow only windows users to use app (no anonymous will access it)--> 
    <authentication mode="Windows" /> 
    <authorization> 
     <deny users="?" /> 
    </authorization> 
    <system.web> 

    <!-- main security, allowing only groups: Clowns and Nerds --> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
     <security> 
      <authorization> 
       <remove users="*" roles="" verbs="" /> 
       <add accessType="Allow" roles="Domain\Clowns" /> 
       <add accessType="Allow" roles="Domain\Nerds" /> 
      </authorization> 
     </security> 
     <defaultDocument enabled="false" /> 
    </system.webServer> 

    <!-- Here we show /images_for_clowns folder ONLY to Clowns group --> 
    <location path="images_for_clowns" inheritInChildApplications="false"> 
    <system.webServer> 
     <validation validateIntegratedModeConfiguration="false" /> 
     <security> 
      <authorization> 
       <clear /> 
       <remove users="*" roles="" verbs="" /> 
       <add accessType="Allow" roles="Domain\Clowns" /> 
      </authorization> 
     </security> 
     <defaultDocument enabled="false" /> 
    </system.webServer> 
    </location> 

    <!-- Here we show /images_for_nerds folder ONLY to Nerds group --> 
    <location path="images_for_nerds" inheritInChildApplications="false"> 
    <system.webServer> 
     <validation validateIntegratedModeConfiguration="false" /> 
     <security> 
      <authorization> 
       <clear /> 
       <remove users="*" roles="" verbs="" /> 
       <add accessType="Allow" roles="Domain\Nerds" /> 
      </authorization> 
     </security> 
     <defaultDocument enabled="false" /> 
    </system.webServer> 
    </location> 

也许另一个伎俩将使用

<location path="."> 
    <system.webServer>... 

为了设置根文件夹的权限!希望这可以帮助更多的人。