我正在做一个.NET服务器文件(.asmx)和客户端界面(.aspx)的Web服务。访问者应该只能访问客户端的aspx站点(urlXXX:portYY/Client.aspx) 但是,当我从URL中删除“/Client.aspx”部分时,我进入了项目目录,这不应该是可能。 (到目前为止,我只是在本地主机上运行该项目。)防止访问其他网络服务
有什么办法,如何限制进入解决方案的其他部分?我能想到的唯一可能是为客户端aspx站点创建一个单独的项目,但即使如此,访问者也能够进入包含该站点的目录。
我正在做一个.NET服务器文件(.asmx)和客户端界面(.aspx)的Web服务。访问者应该只能访问客户端的aspx站点(urlXXX:portYY/Client.aspx) 但是,当我从URL中删除“/Client.aspx”部分时,我进入了项目目录,这不应该是可能。 (到目前为止,我只是在本地主机上运行该项目。)防止访问其他网络服务
有什么办法,如何限制进入解决方案的其他部分?我能想到的唯一可能是为客户端aspx站点创建一个单独的项目,但即使如此,访问者也能够进入包含该站点的目录。
您应该能够使用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更多信息否认在访问明确的文件夹以及。
所以,基本上我设法找到一种解决方法,通过添加以下代码在Web.config:
<system.webServer>
<defaultDocument>
<files>
<add value="Client.aspx" />
</files>
</defaultDocument>
</system.webServer>
...这使得客户端默认的网页,从而防止看该目录。但是,如果有人提供更复杂和更复杂的解决方案,我会将此主题保留开放。
您使用的是什么IIS版本?您可以禁用您的网站的目录浏览。看看[这](http://stackoverflow.com/questions/9806446/disable-directory-listing-in-iis) –
我有IIS 7.5 ...仍然,你的解决方案没有任何效果。 – Storm
你做了什么?你可以像在那个链接中说的那样去做,如果你使用VS进行调试并检查,那么将你的任何页面设置为默认页面。这可能会解决你的问题。 –