How do I get the current Url from within a FilterAttribute?

后端 未结 4 2072
星月不相逢
星月不相逢 2021-02-03 18:17

I am writing an Authorize filter attribute adn I\'m having trouble figuring out how to get the current url as a string so I can pass it as a parameter to the LogOn action. The g

4条回答
  •  情深已故
    2021-02-03 18:50

    This is the highest ranked result on Google so in Asp.net Core 2.0 this is how I'm doing it:

    context.HttpContext.Request.Url();
    

    using this extension method:

    /// 
    /// Returns the absolute url.
    /// 
    public static string Url(this HttpRequest request)
    {
        return $"{request.Scheme}://{request.Host}{request.Path}{request.QueryString}";
    }
    

提交回复
热议问题