开发者

How to get fully qualified path of css file?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜