开发者

How to get fully qualified path of css file?

开发者 https://www.devze.com 2022-12-27 18:33 出处:网络
In ASP.NET MVC how do I get the fully qualified path to my css file by specifying the relative path. Eg

In ASP.NET MVC how do I get the fully qualified path to my css file by specifying the relative path.

Eg

Url.Content("~/Content/Print.css")

This returns eg "/Content/Print.css"

Where as I want

http://www.mysite.com/Content/Printcss

U开发者_如何学运维nderstand the issue?

Malcolm


Similar to Phil, I would use the Request object. However, I would look at the Url property. With the Url, you can call GetLeftPart(UriPartial.Authority) to get the missing part of your address:

string address = 
    System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + 
    Url.Content("~/Content/Print.css");

The GetLeftPart should return "http://www.mysite.com" as shown in the doc: http://msdn.microsoft.com/en-us/library/system.uri.getleftpart(v=VS.100).aspx


I'd probably concatenate Request.UserHostName and your CSS location:

String.Format("{0}/Content/Print.css", Request.UserHostName);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号