ASP MVC Friendly URL's and Relative Path Images

后端 未结 4 626
野趣味
野趣味 2021-01-17 08:19

I have an ASP.NET MVC page, where I am trying to show friendly URL\'s.

So, I have a Category View in the Home Controller, that accepts a categoryKey value to get the

相关标签:
4条回答
  • 2021-01-17 08:32

    This works too.

    <img src="@Url.Content("~/Images/yourimage.png")"/>
    
    0 讨论(0)
  • 2021-01-17 08:35

    You can use the relative path " ~/ " to refer to the current virtual directory where the page is located. Try to add runat="server" attribute to your "img" tag and "~" sign in "src" attribute:

    <img runat="server" src="~/AdminUploadContent/bikes.gif" alt="Bikes" />
    
    0 讨论(0)
  • 2021-01-17 08:38

    You can implement a custom http module that will rewrite path from the relative ../../img.png to needed handling the Referer http header, for instance.

    0 讨论(0)
  • 2021-01-17 08:49

    Use the Url.Content method when generating a path to your image.

    <img src="@Url.Content("~/AdminUploadContent/bikes.gif")" />
    

    or if using the WebForms view engine:

    <img src="<%= Url.Content("~/AdminUploadContent/bikes.gif") %>" />
    
    0 讨论(0)
提交回复
热议问题