htmlasp.neturlhttp-redirectreturnurl

ReturnURL messed up when a page links to itself


I have a home.aspx and about.aspx in the root directory, an Account folder which included login.aspx, register.aspx, manage.aspx.

I have a navbar which includes links to all the relevant pages depending on whether the user is logged in or not. Suppose if he is at the login.aspx page and he clicks again on the link to /login.aspx, the return URL becomes ReturnUrl="localhost:xxxx/Account/Account/login.aspx" If I click on register.aspx now, it becomes Account/Account/Account/register.aspx

What is this called and how to rectify it? I think I need to make something like a virtual root directory relative to which all addresses are resolved.
My hrefs are like this,

<li id="RegisterLink" runat="server"><a href="Account/Register.aspx"><span class="glyphicon glyphicon-user"></span> Register</a></li>
<li id="LoginLink" runat="server"><a href="Account/Login.aspx"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>

Solution

  • I am sharing the below solution from another thread which seems to work in my situation too (Source https://stackoverflow.com/a/3567721/4594699)

    You have a bunch of options:

    1. You could hardcode the Url using the ~ operator which give you the root and then define it from there like: ~/Pages/AboutMe.aspx. Keep in mind that the ~ operator is recognized only for server controls and in server code.

    2. You could also use the .. to get you to where you want as it will navigate back up the folder structure like: ../Pages/AboutMe.aspx

    3. You could create a helper methods to return you a valid root to your Pages folder, Images, Javascript, etc...

    4. The HttpRequest.ApplicationPath will get your the virtual application's root path on the server which you can use to build off.

    For more information on Pathing options you should read this article on MSDN:

    ASP.NET Web Project Paths