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

后端 未结 4 2071
星月不相逢
星月不相逢 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:47

    To get the complete URL you can try as suggested by the @rboarman but usually the RedirectUrl will be the relative url and for that you have to try the the RawUrl property of the Request object.

    filterContext.HttpContext.Request.Url  ===> http://somesite.com/admin/manage
    
    filterContext.HttpContext.Request.RawUrl ====> /admin/manage
    

    EDITED: Fixed the second example

提交回复
热议问题