2012-01-30 130 views
1

目前Url.Content("a.jpg")服務來自不同服務器的內容將返回類似「/a.jpg」在ASP.NET MVC 3應用程序

有沒有辦法強制所有內容被從另一臺服務器提供服務?

我想Url.Content("a.jpg")返回的東西,如:「HTTP:// ,某 /a.jpg」

回答

3

Url.Content幫手只有內部工作以當前應用程序的URL。如果你想與外部URL工作,你可以寫一個自定義的URL幫手這一目的:

public static class UrlExtensions 
{ 
    public static string ContentExternal(this UrlHelper urlHelper, string contentPath) 
    { 
     var uriBuilder = new UriBuilder("http://somehost"); 
     uriBuilder.Path = contentPath; 
     return uriBuilder.ToString(); 
    } 
} 

然後:

@Url.ContentExternal("/Content/images/a.jpg") 
相關問題