简体   繁体   English

iis中主机名的默认页面

[英]Default page for a host name in iis

I have a website with 4 binding in IIS 7.5 我有一个在IIS 7.5中具有4绑定的网站

I want if user use {Host Name 1} then default document be {Default1.aspx} 我想如果用户使用{主机名1},则默认文档为{Default1.aspx}

I want if user use {Host Name 2} then default document be {page/Default1.aspx} 我想如果用户使用{主机名2},则默认文档为{page / Default1.aspx}

I want if user use {Host Name 3} then default document be {page/admin/Default3.aspx} 我想如果用户使用{主机名3},则默认文档为{page / admin / Default3.aspx}

How do I implement ? 我该如何实施?

thanks 谢谢

You have 3 different ways that you can use. 您有3种不同的使用方式。

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. 您在global.asax捕获BeginRequest,然后在其中实现您的逻辑, 例如使用RewritePath ,这是您需要测试和发展的示例。

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 还有一篇关于msdn 将用户重定向到另一页的文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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