converting virtual path to actual web path in ASP.NET

后端 未结 3 1614
太阳男子
太阳男子 2021-01-30 21:32

I have a virtual path (example: \"~/Images/Banner.jpg\") and I want to make that an absolute web path (example: \"/ApplicationRoot/Images/Banner.jpg\"). There is a method tha

相关标签:
3条回答
  • 2021-01-30 22:09

    There are various ways that are available in ASP.NET that we can use to resolve relative paths to absolute Urls -

    1) Request.ApplicationPath
    2) System.Web.VirtualPathUtility
    3) Page.ResolveUrl
    4) Page.ResolveClientUrl

    Here's a article that explains the difference between the various ways to resolving paths in ASP.NET -

    Different approaches for resolving URLs in ASP.NET

    0 讨论(0)
  • 2021-01-30 22:14
    Control.ResolveClientUrl(url)
    

    or

    Control.ResolveUrl(url)
    

    Whichever one you need (honestly I dont know the difference, as both seem to return mostly the same, perhaps someone can illuminate me :) ).

    0 讨论(0)
  • 2021-01-30 22:17
    System.Web.VirtualPathUtility.ToAbsolute("yourRelativePath");
    

    There you go :)

    0 讨论(0)
提交回复
热议问题