Request class is not available in a Razor Page

Viewed 1554

I am working on ASP.NET Core 2.1 and I want to use Request class in razor page to get current domain by the following code:

@Request.Url.Authority

But Request is not recognized in razor page. How can I access to Request class in razor page? Thanks for any help.

1 Answers

Request should be available in a Razor page. You might be trying to use Request is a partial view, where it's not present. Try accessing it from the Context property which contains the current HttpContext:

@Context.Request.Url.Authority
Related