2012-03-28 65 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>... 

爲了設置根文件夾的權限!希望這可以幫助更多的人。