当页面链接到自身时 ReturnURL 搞砸了

ReturnURL messed up when a page links to itself

我在根目录中有一个home.aspxabout.aspx,一个帐户文件夹,其中包括login.aspxregister.aspxmanage.aspx.

我有一个导航栏,其中包含 link 到所有相关页面,具体取决于用户是否登录。 假设如果他在 login.aspx 页面,他再次点击 link 到 /login.aspx,return URL 变成 ReturnUrl="localhost:xxxx/Account/Account/login.aspx" 如果我现在点击 register.aspx,它会变成 Account/Account/Account/register.aspx

这叫什么,怎么改? 我想我需要创建一个虚拟根目录之类的东西,所有地址都相对于该目录进行解析。
我的 href 是这样的,

<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>

您使用相对锚而不是绝对锚。 尝试更改:

<a href="Account/Register.aspx">

收件人:

<a href="/Account/Register.aspx">

你也可以试试这个:

<a href="../config2.aspx">

如果您删除该帐户,也许会修复它:

<a href="Register.aspx">

或者试试这个:

<a href="~/Account/Register.aspx">

或以其他方式整理文件夹。

我正在从另一个线程分享以下解决方案,它似乎也适用于我的情况(来源 )

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