大网数据广告活动
Web服务器与PHP

Restrict users from accessing to web resources

· 52CE 我爱测

This article describes some methods about restricting specific users from gaining access to specified web resources.

This article describes methods about how to restrict specific users from gaining access to specified web resources.

Original product version:   ASP.NET
Original KB number:   815151

Summary

Web applications that are based on ASP.NET provide many ways for users to be authenticated and authorized to gain access to resources. The way that you restrict access to resources varies, depending on the authentication method that you use. For example, for an application where you use Microsoft Windows authentication and you enable impersonation, you can use New Technology File System (NTFS) file permissions for access control. However, for an application where you use forms authentication, you must modify the Web.config file to restrict access. This article describes how to control authorization for both of these ASP.NET authentication methods.

Control authorization by using file permissions

For ASP.NET web applications where you use Windows authentication and you enable impersonation, you can use standard NTFS file permissions to require authentication and to restrict access to the files and folders:

  • To require authentication, remove the ASPNET user account's access permissions for the file or folder.
  • To restrict access to specific Windows user accounts or group accounts, grant or deny Read NTFS file permissions to files or folders.

Control authorization by modifying the Web.config file

To restrict access to ASP.NET applications that use forms authentication, edit the <authorization> element in the application's Web.config file. To do this, follow these steps:

  1. Start a text editor, such as Notepad, and then open the Web.config file that is located in the application's root folder.

    [!NOTE] If the Web.config file doesn't exist, create a Web.config file for the ASP.NET application.

  2. If you want to control authorization for the whole application, add the <authorization> configuration element to the <system.web> element in the Web.config file.

  3. In the <authorization> element, add the <allow> configuration element and the <deny> configuration element. Use the users attribute to specify a comma-delimited list of user names. You can use a question mark (?) as a wildcard character that matches any user name. For example, the following code denies access to all users except user1 and user2:

    <authorization>
        <allow users="user1, user2"/>
        <deny users="?"/>
    </authorization>
    
  4. Save the Web.config file.

References

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 03/26/2020
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。