2013-09-26 54 views

回答

2

你應該這樣做有web.config。放置在images文件夾中的配置文件的內容是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.web> 
     <authorization> 
      <deny users ="?" /> <!--Deny all users who are anonymous (not logged in) --> 
     </authorization> 
    </system.web> 
</configuration> 

要使用主web.config文件爲您的應用程序,請執行以下操作:

<location path="Images"> 
    <system.web> 
     <authorization> 
      <deny users ="?" /> 
     </authorization> 
    </system.web> 
</location> 
+0

我們可以在MVC 4中使用相同的網絡配置嗎? –

+0

@ user2819626看我的編輯。 – Mansfield

+0

它不適用於MVC 4 Web配置。用戶可以通過直接URL路徑瀏覽圖像文件http://xyz.com/Images/Image.png –

1

限制文件夾配置如下配置塊在Web.config

<configuration> 
<location path="ImageDirectory"> 
    <system.web> 
     <authorization> 
      <deny users="*"/> <!-- Denies all users --> 
     </authorization> 
    </system.web> 
</location> 
</configuration> 

按照上述配置匿名用戶無法訪問ImageDirectory文件夾及其內容。

+0

它在沒有MVC的asp.net中工作。 –

+0

您也可以在MVC中使用相同的方法。 –

相關問題