Reputation: 21
How could we get the current page URL in .cshtml page for Kentico 13.
Used @Context.Request.GetDisplayUrl().ToString() but getting the below error 'HttpRequest' does not contain a definition for 'GetDisplayUrl' and no accessible extension method 'GetDisplayUrl' accepting a first argument of type 'HttpRequest' could be found (are you missing a using directive or an assembly reference?)
Upvotes: -1
Views: 927
Reputation: 61
I usually do this with the IPageUrlRetriever.
This needs the current document, which you could get with the IPageDataContextRetriever.
I would invoke both in your controller and put the result into your viewmodel, but you can also invoke both in yout cshtml file only by using CMS.Core.Servive.Resolve().
Upvotes: 0
Reputation: 6117
I highly recommend checking out the Dancing Goat example which you can install (on your local machine using Xperience Installation Manager) to get some insipration from. To answer your question specifically, you can use this to achieve what your screenshot is showing for the canonical URL:
<link rel="canonical" href="@Url.Kentico().PageCanonicalUrl()" />
Upvotes: 1
Reputation: 21
Use this namespace "@using Microsoft.AspNetCore.Http.Extensions" see the image for better experiance
Upvotes: 2