Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Stop redirect from root to default.aspx

  • 28-02-2010 05:03PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Could you write a HttpModule to handle it for you?


  • Registered Users, Registered Users 2 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