简体   繁体   中英

Default page for a host name in iis

I have a website with 4 binding in IIS 7.5

I want if user use {Host Name 1} then default document be {Default1.aspx}

I want if user use {Host Name 2} then default document be {page/Default1.aspx}

I want if user use {Host Name 3} then default document be {page/admin/Default3.aspx}

How do I implement ?

thanks

You have 3 different ways that you can use.

Each one have their positives and negatives. You capture on global.asax the BeginRequest, and there you implement your logic, for example using RewritePath , an example that you need to test and evolve.

protected void Application_BeginRequest(Object sender, EventArgs e) 
{
    string sTheFile = HttpContext.Current.Request.Path;
    string sExtentionOfThisFile = System.IO.Path.GetExtension(sTheFile);

    if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
    {
        if(Request.Url.Host == "www.hostname2.com")
        {           
            HttpContext.Current.RewritePath("/page/default1.aspx", false);          
        }
        else if(Request.Url.Host == "www.hostname3.com")
        {
            HttpContext.Current.RewritePath("/page/admin/Default3.aspx", false);
        }
        else
        {
            // for default1.aspx - leave it as is       
        }       
    }
}

And one article on msdn Redirect Users to Another Page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM