How to configure the ASP.net application in IIS 7.0

Source: Internet
Author: User
Tags command line config configuration settings datetime iis tostring visual studio

If the ASP.net Web application is hosted with IIS 7.0, you can configure the application in a variety of ways. This includes:

Use IIS Manager.

Edit the web.config file directly. You can accomplish this task either in visual Studio or in the visual Web Developer or by using a text-editing program.

Use the IIS 7.0 command line tool (Appcmd.exe). Using this utility, you can specify IIS configuration settings and Web application configuration settings.

Use Windows Management Instrumentation (WMI). The IIS 7.0 WMI provider webadministration namespaces contain classes and methods that you can use to create scripts for administrative tasks for Web sites, Web applications, and their associated objects and properties.

IIS 7.0 has a modular architecture that enables you to specify which modules make up the functionality of a WEB server. When IIS 7.0 is installed, many modules are not enabled by default. When you use the ASP.net web site, you may need to enable the following modules:

IIS 6 manages the Compatibility module, which enables Visual Studio to interact with the IIS 7.0 configuration store using metabase calls.

Windows authentication module, which enables you to debug WEB applications in Visual Studio

First, in this walkthrough, you will use IIS Manager for configuration settings, and then see how these settings are reflected in the Web.config file for the Web application. The tasks that are illustrated in this walkthrough include the following:

Create a custom managed code module and place the module in the App_Code directory of the WEB application.

Register the custom module with IIS Manager.

Use IIS Manager to add custom HTTP headers.

The functionality of this module is not important in this walkthrough. This walkthrough will demonstrate how to integrate the module into the request pipeline, and how the use of IIS Manager to configure the application will affect the Web.config file.

First, create a custom HTTP module

First, you need to create a new Web site.

Create a new Web site

In Visual Studio, create a new local HTTP Web site named "WalkthroughIIS7."

For information about how to create a local IIS Web site, see Walkthrough: Creating a Local IIS Web site in the Visual Web Developer.

On the Start menu, click All Programs, then attachments, and then run.

In the Open box, type inetmgr, and then click OK.

You can now create a custom HTTP module.

Creating a custom HTTP module

In Visual Studio, in Solution Explorer, right-click the Web project node, and then click Add New Item.

The Add New Item dialog box appears.

Under Visual Studio installed templates, select classes.

Select the programming language you want to use.

Enter "CustomModule" as the class name, and then click Add.

If the Web site does not already contain the App_Code folder, a message appears asking if you want to put the class in the App_Code folder. If the answer is yes, click Yes.

In the class file, remove the existing code and replace it with the following code:

public class Custommodule:ihttpmodule
{public
    custommodule ()
    {
        //constructor
    }
    Public void Init (HttpApplication app)
    {
        app. BeginRequest + + new EventHandler (beginrequest);
    }
    public void BeginRequest (object source, EventArgs e)
    {
    
        HttpApplication app = (HttpApplication) source;
        HttpContext cont = App. context;
        String notification = Cont. Currentnotification.tostring ();
        String postnotification = Cont. Ispostnotification.tostring ();
        Cont. Response.Headers.Set ("CustomHeader2", "ASPX, Event =" + notification +
                ", postnotification =" + postnotification +< c18/> ", DateTime =" + DateTime.Now.ToString ());
    
    }
    public void Dispose ()
    {
    }
}

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.