Get absolute path of file on content

前端 未结 5 664
轮回少年
轮回少年 2020-12-15 03:58

Is there any easy (built in) way in an asp.net mvc view to get the absolute path of a file in the content folder?

At the moment I\'m using

@Url.Cont         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 04:47

    This will generate an absolute url to an image (or file)

    Request.Url.Scheme + "://" + Request.Url.Authority + Url.Content("~/Content/images/logo.png")
    

    This works in Asp.net Core

    Context.Request.Scheme + "://" + Context.Request.Host + Url.Content("~/images/logo.png")
    

提交回复
热议问题