【问题标题】:assign port number to localhost将端口号分配给 localhost
【发布时间】:2018-05-30 08:26:43
【问题描述】:

我的应用程序中有一个 URL http://localhost/Login.aspx 不起作用:

<a href='http://localhost/Login.aspx'>Login</a>

但它适用于:

<a href='http://localhost:51807/Login.aspx'>Login</a>

问题是:

当用户点击登录&lt;a href='http://localhost/Login.aspx'&gt;Login&lt;/a&gt;&lt;a href='http://localhost/Login.aspx'&gt;Login&lt;/a&gt;时,如何将端口号51807分配给URLhttp://localhost/Login.aspx

【问题讨论】:

  • 为什么在链接中使用http://localhost
  • 因为链接在我的本地机器上。
  • 登录 ?
  • url 更改为 localhost:51807/~/Login.aspx 并表示找到的页面。
  • 抱歉,我不太熟悉 ASP.NET,无法理解您的问题。希望这个搜索能以某种方式帮助你bing.com/…

标签: c# html asp.net localhost


【解决方案1】:

使用相对链接

<a href='./Login.aspx'>Login</a>

【讨论】:

    【解决方案2】:

    端口号由Visual Studio在项目创建过程中生成,以避免同时开发/调试多个Web应用程序时的端口冲突。这个临时端口不会影响您在生产中的部署

    关于您的问题,请考虑使用&lt;asp:HyperLink&gt; 生成链接,而不是使用纯html &lt;a&gt; 标签,例如:

    <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

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 2013-01-09
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多