2013-07-11 291 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> 

...这使得客户端默认的网页,从而防止看该目录。但是,如果有人提供更复杂和更复杂的解决方案,我会将此主题保留开放。