IIS 6 ignores Web.config authorization settings

﹥>﹥吖頭↗ 提交于 2019-11-30 16:24:40

It looks like IIS does not forward the request for .xml or .txt files to ASP.NET, so it has no chance to apply its authorization controls.

To work around this, I had to do the following (from this forum post):

  1. From IIS Console, open properties of the virtual directory of my app.
  2. Virtual Directory > Configuration
  3. Add new handler for extension ".xml" using the ASP.NET filter (c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll in my case)
  4. All verbs. Uncheck both "Script engine" and "Verify that file exists".

Is there any way to do this from within Web.config?

Try this:

<location path="hibernate.cfg.xml">
    <system.web>
      <authorization>
        <deny users="?"/>
        <deny users="*"/>
      </authorization>
    </system.web>
</location>

Static files such as .jpg, .xml and .pdf are by default handled directly by the kernel mode http.sys driver. Unless you've mapped these extensions to ASP.NET they will never hit the ASP.NET pipeline and hence the authorisation mechanism within ASP.NET.

To force static files such as .xml to be processed by .NET on .NET 2.0/3.5/4.0 and IIS6, do the following:

1) Add the entries for.xml (or other file type) to IIS as described above (IIS6 website properties, Home Directory, Configuration)

2) in web.config add the location for the restricted directory or file

<location path="directory_or_file_name">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
</location>

3) Add the following to the httpHandlers section:

<add path="*.xml" verb="*" type="System.Web.StaticFileHandler" validate="true" />

This will force .NET to only serve .xml files as specified in the <location> tag to authenticated users.

URL Authorization: The URLAuthorizationModule class is responsible for URL authorization on Windows 2003. This mechanism uses the URL namespace to store user details and access roles. The URL authorization is available for use at any time. You store authorization information in a special XML file in a directory. The file contains tags to allow or deny access to the directory for specific users or groups. Unless specified, the tags also apply to subdirectories.

You need to do the following:

<deny users="?"/>
<deny users="*"/>

The wild card entry "?" means that no one else will be able to gain access to this directory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!