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

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

Writing

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

in razor renders

/AppFolder/Something/Something.html

I

4条回答
  •  佛祖请我去吃肉
    2021-02-07 02:26

    For anyone needing to build URLs in WebAPI 2.2 and/or MVC5, this worked for me:

    // works in a controller
    var requestUri = this.Request.RequestUri;
    // just the http/s and the hostname; ymmv
    string baseUrl = requestUri.Scheme + "://" + requestUri.Authority + "/";
    // build your url for whatever purpose you need it for
    string url = baseUrl + "SomeOtherController?id=" + ;
    

提交回复
热议问题