Request.Url fail in a Razor page (VS2022 / .Net 6)

William He 1 Reputation point
2022-03-24T09:11:19.647+00:00

I use Microsoft Learn sample code in my Razor page. But I get CS1061 error message from VS2022. Is there any wrong? Or how can I get current URL in the same environment. Thanks.

---------------------------
Code-------------------------
@Anonymous

@man_man9987 .Url <br />
@man_man9987 .FilePath<br />
@man_man9987 .MapPath(Request.FilePath)<br />
@man_man9987 .RequestType

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,188 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lohith GN 511 Reputation points
    2022-04-11T00:16:14.063+00:00

    @williamHe-27

    as @Zhi Lv - MSFT pointed out, you have @man_man9987 object that you can make use of.

    Here is the official documentation for Requets object: https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httprequest?view=aspnetcore-6.0#properties

    One such property of Request is PATH. You will have to use it like @man_man9987 .Path. this will get you the request path of the current request.

    For e.g. if the request was for https://www.yourdomain.com/people/lohith - @man_man9987 .Path will return /people/lohith

    Hope this helps.

    Note: Please mark this as an Answer, if your question/issue was solved. Thanks.

    0 comments No comments