What is the ASP.NET Core MVC equivalent to Request.RequestURI?

后端 未结 3 1460
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 14:11

I found a blog post that shows how to \"shim\" familiar things like HttpResponseMessage back into ASP.NET Core MVC, but I want to know what\'s the new native way to do the s

3条回答
  •  春和景丽
    2020-12-14 14:53

    A cleaner way would be to use a UriBuilder:

    private static Uri GetUri(HttpRequest request)
    {
        var builder = new UriBuilder();
        builder.Scheme = request.Scheme;
        builder.Host = request.Host.Value;
        builder.Path = request.Path;
        builder.Query = request.QueryString.ToUriComponent();
        return builder.Uri;
    }
    

    (not tested, the code might require a few adjustments)

提交回复
热议问题