asp.net mvc image path and virtual directory

后端 未结 4 1734
死守一世寂寞
死守一世寂寞 2021-02-11 02:59

I know this has to be a duplicate, but I\'ve been wading through the hordes of information on this and I can\'t get it work.

I\'m trying to get a site working on a clien

4条回答
  •  逝去的感伤
    2021-02-11 03:29

    You could write a small extension method:

    public static class UrlExtensions
    {
        public static string AbsoluteContent(this UrlHelper url, string contentPath)
        {
            var requestUrl = url.RequestContext.HttpContext.Request.Url;
            return string.Format(
                "{0}{1}",
                requestUrl.GetLeftPart(UriPartial.Authority),
                url.Content(contentPath)
            );
        }
    }
    

    and then:

    " />
    

    which will output for example:

    
    

提交回复
热议问题