ASP.NET relative path

后端 未结 3 613
旧时难觅i
旧时难觅i 2021-02-12 12:35

I\'m confused with ASP.NET relative path, please can someone help?

In a Master Page I gave a link label referencing:



        
相关标签:
3条回答
  • 2021-02-12 13:04

    You can use ~ when refering to URLs inside ASP.NET Server Controls. You are using it in a <a> tag which is just plain html that doeesn't know anything about ~ . use '"/Images/SampleImage.jpg"' instead

    0 讨论(0)
  • 2021-02-12 13:06

    Because you're using it directly in markup, rather than in a server control. Something as simple as this should fix it:

    <a runat="server" href="~/Account/Login.aspx">Login</a>
    

    Basically, the ~ path reference needs to be translated on the server, since it's a reference to the server path of the application's base directory. Plain HTML markup isn't processed on the server, it's just delivered as-is to the client. Only server-processed code will translate the ~ path to what it resolves to.

    0 讨论(0)
  • 2021-02-12 13:10

    use this command

    <a href="<%=Page.ResolveUrl("~/product.aspx")%>" >Link To Products</a>
    
    0 讨论(0)
提交回复
热议问题