Get raw URL from Microsoft.AspNet.Http.HttpRequest

后端 未结 8 793
醉酒成梦
醉酒成梦 2020-12-02 21:40

The HttpRequest class in Asp.Net 5 (vNext) contains (amongst other things) parsed details about the URL for the request, such as Scheme, Host

8条回答
  •  心在旅途
    2020-12-02 22:22

    Add the Nuget package / using:

    using Microsoft.AspNetCore.Http.Extensions; 
    

    (In ASP.NET Core RC1 this was in Microsoft.AspNet.Http.Extensions)

    then you can get the full http request url by executing:

    var url = httpContext.Request.GetEncodedUrl();
    

    or

    var url = httpContext.Request.GetDisplayUrl();
    

    depending on the purposes.

提交回复
热议问题