How to get the current url in a Razor template served by NancyFX?

According to this answer, the way to do it in MVC Razor is @Request.RawUrl , @Request.Url.ToString() or @Request.Url.AbsoluteUri .

On my razor page, ReSharper resolves @Request to using @Nancy , and I cannot find an instance of HttpRequestBase.RawUrl .

How to get RawUrl from a template served by Nancy?

+7
razor nancy
source share
1 answer

Currently, you will either have to set it to your ViewModel , or get your own page base class from the NancyRazorViewBase<TModel> class and set it from the RenderContext.Context.Request.Url property

Here you can see an example of creating your own base class https://github.com/NancyFx/Nancy/blob/master/src/Nancy.ViewEngines.Razor.Tests/GreetingViewBase.cs

I just sent a pull request with a code change, which makes the following possible from the Razor views https://github.com/NancyFx/Nancy/pull/1633

 @Request.Url @Context.Request.Url 

Once the pull-request is accepted, you can use it using our builds to reduce bleeding https://www.myget.org/gallery/nancyfx

It will then be part of the Nancy v1-alpha release on the official Nuget channel, as soon as we release this

+8
source share

All Articles