asp.nethttp-redirectsubdirectoryreroute

Hosting an ASP.net application on a subfolder


I got a hosting space with Godaddy and I have multiple domain names referring to the same host space.

One of the application is an ASP.net and is located in a subfolder with the domain name related referring to that subfolder.

So www.mydomain.com is referring to <hosting-space-root>\myapp

I found that sometimes the application is correctly handling redirections: e.g. www.mydomain.com/Default.aspx links to www.mydomain.com/Other.aspx

But some other times, the links jumps to a url similar to:

www.mydomain.com/myapp/Other.aspx

Which works fine with no errors, but doesn't look nice.

What is the reason for that and how to handle it?

The application is non-MVC and is actually a very simple one. Do I need to do rerouting and/or implement IHttpModule? Or is there a simple configuration to tell ASP.net that is your root folder use it?


Solution

  • In your comment, you state:

    ...the ones that are redirecting to the URLs with appending the subfolder, are the ones that are server side e.g. <asp:LinkButton runat="server" PostBackUrl="Other.aspx" />

    You should us the ~/ syntax to create relative URLs (relative to your application root, that is). That should resolve the issue you're having with server controls. Like this:

    <asp:LinkButton runat="server" PostBackUrl="~/Other.aspx" />