2013-07-11 268 views
0

我正在做一個.NET服務器文件(.asmx)和客戶端界面(.aspx)的Web服務。訪問者應該只能訪問客戶端的aspx站點(urlXXX:portYY/Client.aspx) 但是,當我從URL中刪除「/Client.aspx」部分時,我進入了項目目錄,這不應該是可能。 (到目前爲止,我只是在本地主機上運行該項目。)防止訪問其他網絡服務

有什麼辦法,如何限制進入解決方案的其他部分?我能想到的唯一可能是爲客戶端aspx站點創建一個單獨的項目,但即使如此,訪問者也能夠進入包含該站點的目錄。

+0

您使用的是什麼IIS版本?您可以禁用您的網站的目錄瀏覽。看看[這](http://stackoverflow.com/questions/9806446/disable-directory-listing-in-iis) –

+0

我有IIS 7.5 ...仍然,你的解決方案沒有任何效果。 – Storm

+0

你做了什麼?你可以像在那個鏈接中說的那樣去做,如果你使用VS進行調試並檢查,那麼將你的任何頁面設置爲默認頁面。這可能會解決你的問題。 –

回答

1

您應該能夠使用web.config控制顯式訪問。看看下面這個例子(exclaimer:我已經複製此直接從this MS page):

<configuration> 
    <system.web> 
     <authentication mode="Forms" > 
      <forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" > 
      </forms> 
     </authentication> 
<!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. --> 
     <authorization> 
      <deny users="?" /> 
     </authorization> 
    </system.web> 
<!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. --> 
     <location path="default1.aspx"> 
     <system.web> 
     <authorization> 
      <allow users ="*" /> 
     </authorization> 
     </system.web> 
     </location> 
<!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder. --> 
     <location path="subdir1"> 
     <system.web> 
     <authorization> 
      <allow users ="*" /> 
     </authorization> 
     </system.web> 
     </location> 
</configuration> 

編輯:看看this question更多信息否認在訪問明確的文件夾以及。

+0

我已經試過了,但不知何故,我仍然能夠進入幾乎所有的目錄,甚至一些文本和XML文件,存儲在它們裏面。 – Storm

+0

添加了指向另一個問題的鏈接,指出如何拒絕對文件夾的訪問。這種做法通常是全面禁止訪問文件夾,然後明確添加要提供的文件。 – Nick

0

所以,基本上我設法找到一種解決方法,通過添加以下代碼在Web.config:

<system.webServer> 
    <defaultDocument> 
     <files> 
      <add value="Client.aspx" /> 
     </files> 
    </defaultDocument> 
</system.webServer> 

...這使得客戶端默認的網頁,從而防止看該目錄。但是,如果有人提供更復雜和更復雜的解決方案,我會將此主題保留開放。