Url helper for full url in asp.net mvc-3

前端 未结 4 1740
离开以前
离开以前 2021-02-07 01:52

Writing

@Url.Content(\"~/Something/Something.html\")

in razor renders

/AppFolder/Something/Something.html

I

4条回答
  •  [愿得一人]
    2021-02-07 02:36

    You can use a helper to produce a full url, including protocol. Note the first lowercase in url.Action.

    var url = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
    var fullUrl = url.Action("YourAction", "YourController", new { id = something }, protocol: System.Web.HttpContext.Current.Request.Url.Scheme);
    

    Output

    https://www.yourdomain.com/YourController/YourAction?id=something

提交回复
热议问题