我的应用程序中有一个URL http://localhost/Login.aspx
无效:
<a href='http://localhost/Login.aspx'>Login</a>
但它适用于:
<a href='http://localhost:51807/Login.aspx'>Login</a>
当用户点击登录51807
时,如何将端口号http://localhost/Login.aspx
分配给URL <a href='http://localhost/Login.aspx'>Login</a>
?
使用相对链接
<a href='./Login.aspx'>Login</a>
端口号由visual studio在项目创建期间生成,以避免在同时开发/调试多个Web应用程序时发生端口冲突。此临时端口不会影响您在生产中的部署
关于你的问题,考虑使用<asp:HyperLink>
生成链接而不是使用普通的html <a>
标签,例如:
<asp:HyperLink runat="server" NavigateUrl="~/Login.aspx">Login</asp:HyperLink>
ASP.NET会将url中的~
转换为Web应用程序的实际根路径,确保链接始终相对于根路径。
例如在你的情况下http://localhost:51807/Login.aspx
或者在生产中生产http://some.domain/Login.aspx
,
或者如果您的Web应用程序部署为虚拟应用程序http://some.domain/virtualapp/Login.aspx