【问题标题】:Force Access Control on web server resource强制对 Web 服务器资源进行访问控制
【发布时间】:2015-07-06 07:19:32
【问题描述】:

我在 IIS 上部署了一个 Web 应用程序,其 IP 域为 192.168.0.105:1009。 用户在应用程序中使用用户名和密码进行登录验证,用户名和密码保存在数据库中。

应用程序中有一个文件夹说MyResource。如何控制此文件夹对任何未经授权的用户的访问控制。

如果有人键入 url 192.168.0.105:1009/MyResource/1.xls,它应该验证用户身份验证。如果用户未经授权,则应拒绝访问。

【问题讨论】:

  • 将 web.conifig 放入带有所需授权标签的文件夹中。
  • 您应该在您的 web.config 文件中使用身份验证和授权,并在您的应用程序中进行滚动管理。
  • 详细解释请查看我的回答。

标签: c# asp.net authentication iis


【解决方案1】:

您可以按照以下说明进行操作。

配置对特定文件和文件夹的访问,设置基于表单的身份验证。

请求将应用程序中的任何页面自动重定向到 Logon.aspx。

Web.config 文件中,键入或粘贴以下代码。

此代码授予所有用户访问Default1.aspx pageSubdir1 folder 的权限。

<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>

用户可以在您的应用程序中打开 Default1.aspx 文件或保存在 Subdir1 文件夹中的任何其他文件。它们不会被自动重定向到 Logon.aspx 文件进行身份验证。

重复配置步骤以识别您希望允许未经身份验证的用户访问的任何其他页面或文件夹。

更多参考请查看微软支持页面 - https://support.microsoft.com/en-us/kb/301240

您也可以查看http://www.iis.net/configreference/system.webserver/security/authorization

【讨论】:

  • 感谢您的回复.. web.config 如何知道授权和未授权用户。我的意思是什么定义了 web.config 的授权和未授权用户。
  • @RajeevKumar 您必须在登录页面按钮单击上定义表单身份验证票证代码 - 供参考检查 -> codeproject.com/Articles/13872/…
猜你喜欢
  • 2010-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 2019-09-05
  • 2017-06-19
  • 2017-02-16
相关资源
最近更新 更多