Writing
@Url.Content("~/Something/Something.html")
in razor renders
/AppFolder/Something/Something.html
Is there a way to render the full URL like http://www.something.com/AppFolder/Something/Something.html
without atrocious hacks? (like storing the protocol and domain in the AppConfig
, and concatenate the string to it)
Is there a helper like @Url.FullPath("~/asdf/asdf")
or similar?
See this blog post for the answer.
Basically, all you need to do it include the protocol parameter e.g.
The @Url.RouteURL() does not quiet answer this question. It does work for named routes but falls short for arbitrary virtual paths. Here is quick helper method that generates full outbound url. You can create overloads for various schemes (http[s]) depending on the degree of control desired.
For anyone needing to build URLs in WebAPI 2.2 and/or MVC5, this worked for me: