0

How to configure my website that can be accessible using url like http://sitename.servername.com

Currently I am able to access my site using http://servername.com/Sitename/default.aspx, but I want to use . notation instead of /

I am using ASP.NET 4.0 with IIS 7.5 on Windows Server 2008 R2.

Thanks.

Atul K
  • 53
  • 2
  • 9

1 Answers1

0

use the following code in Global.asax

public class Global : System.Web.HttpApplication
{
    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Request.Url.AbsolutePath.EndsWith("/"))
        {
            Server.Transfer(Request.Url.AbsolutePath + "default.aspx");
        }
    }
}
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • I would say setting a default document is enough: http://stackoverflow.com/questions/1913058/set-default-page-in-asp-net – Wiktor Zychla Aug 04 '14 at 12:05
  • 1
    Setting default document will not work when the site runs under the 3rd party live servers. The above solution will always redirect it to the default page, whatsoever be the environment it is running on – Abhishek Singh Aug 04 '14 at 12:23
  • Are you sure the above solution is right? It doesn't seem to catch the `http://foo.bar` without ending `/` but also seem to wrongly catch all other uris that end with `/` (`http://foo.bar/qux/`). – Wiktor Zychla Aug 04 '14 at 12:47
  • I have no issue accessing web pages but with domain name. I believe this can be solved by either creating sub-domain or changing .config file or by changing host file? – Atul K Aug 04 '14 at 12:56
  • @user2345851: Domains are handled by dns servers, this is where you need to modify the configuration. Then, set a new host name in the application configuration in iis. – Wiktor Zychla Aug 04 '14 at 15:15