How to configure access verification for HTML pages in ASP. NET, and asp.net

Source: Internet
Author: User

How to configure access verification for HTML pages in ASP. NET, and asp.net

Many of my friends may not notice this problem like me.. NET, uses its own access authentication functions (Form Verification, Passport verification, Windows verification), and does not apply to static files (such as html, image files, text files, etc) allows anonymous users to access these files even if they are placed in a folder that requires authentication before they can be accessed. This is because static files are processed by IIS by default. After IIS receives a request for these files, it will not be transferred to ASP. NET Processing, so, in ASP.. NET. In other words, these files are not under the jurisdiction of ASP. NET.

So, how to put these files under the jurisdiction of ASP. NET? Take an html file as an example. The simplest way is to change the suffix of an html file to aspx. This method is simple, practical, but not formal. Another method is to configure IIS so that IIS can transfer the html file processing permission to ASP. NET. The settings are as follows:

(1) Open IIS, find the ASP. NET application to be set, and open the Properties dialog box.

(2) On the "virtual directory" tab, there is an "Application Settings". Click the "Settings" button to bring up a new dialog box.

(3) On the "" tab, click the "add" button to add the. htm suffix and the corresponding processing program. For specific settings, see. aspx settings.

After the settings are complete, access the html file located in the directory to be verified again and go to the logon page to prompt the user to log on, indicating that the access verification has taken effect. However, the htm file is incorrect after logon. This involves HttpHandler, because for ASP. NET, this is equivalent to enabling a new file type, but there is no corresponding processing program. Therefore, you also need to modify the settings of web. config to register a new handler. For html files, we can use the aspx file handler, so the settings are as follows:

<System. web>... 

Again, this is a compilation error because the corresponding Compilation Program for the htm file is missing, and then modify web. config:

<System. web> <compilation>... <! -- Set the Compilation Program of the file with the suffix htm. Here we use the Compilation Program of the aspx file --> <buildPRoviders> <add extension = ". htm "type =" System. web. compilation. pageBuildProvider "/> </buildProviders> </compilation>... </system. web>

Access this html file again this time. As we expected, it requires authentication and can be properly displayed. In fact, the core of this problem lies in the understanding of HttpHandler. In addition, it is said that in IIS7, the problem can be solved by placing the application in an Integrated application pool.

If you do not have special requirements or want to use HTML static pages, it is relatively easy to convert html to aspx. The customer does not need to make too many configurations to deploy the system. Some customers will be annoyed to deploy the system for configuration, so it is better to make the deployment simple.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.