Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Stop redirect from root to default.aspx

Options
  • 28-02-2010 5:03pm
    #1
    Registered Users Posts: 128 ✭✭


    Hi,

    I have an ASP.NET website and I'm trying to stop the server redirecting the root '/' to the default page '/default.aspx'. I'm on a shared host so I don't have access to IIS. Is there any way of doing this in the code or the web.config file?


Comments

  • Closed Accounts Posts: 1,759 ✭✭✭Dr.Silly


    Hi,

    Only if it's IIS 7.

    <configuration>
    <system.webServer>
    <defaultDocument>
    <files>
    <add value="YOURNEWPAGE.ASPX" />
    </files>
    </defaultDocument>
    </system.webServer>
    </configuration>

    If you're using II6, don't know of another way other than URL mapping.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Could you write a HttpModule to handle it for you?


  • Registered Users Posts: 128 ✭✭johnny_rambo


    Dr.Silly wrote: »
    Hi,

    Only if it's IIS 7.

    <configuration>
    <system.webServer>
    <defaultDocument>
    <files>
    <add value="YOURNEWPAGE.ASPX" />
    </files>
    </defaultDocument>
    </system.webServer>
    </configuration>

    If you're using II6, don't know of another way other than URL mapping.

    This doesn't work on GoDaddy (IIS7). Is there something that needs to be configured server side?
    Could you write a HttpModule to handle it for you?
    I don't know if this will work....I'll look into it before I start coding it.

    I thought this would be an easy thing to fix but it's proving to be a bit of a pain in the ass!


  • Closed Accounts Posts: 22 paul.mcguinness


    Just create the default.aspx with inline code, remove the (Inherits="website.whatever")"

    and place this directly in the aspx file so you wont need to compile it to your project dll
    <script runat=server language=cs>
    protected override void  OnInit(EventArgs e)
    {
      string host = this.Request.ServerVariables["HTTP_HOST"];
          if ((host.ToLower().Contains("default.aspx"))
        {
                  Response.Clear();
                  Response.Buffer = true;
                  Response.BufferOutput = true;
                  Response.Status = "301 Moved Permanently";
                  Response.AddHeader("Location", "http://www.Yourwebsite.ie/mynewindex.aspx");
                  Response.Flush();
                  Response.End();
    }
    
    </script>
    


Advertisement