UmbracoContext helper
The UmbracoContext is a helpful service provided on each request to the website
The UmbracoContext is the simplified way to work with the current request on your website.
You can use UmbracoContext to access the content and media cache. Other useful properties are the original and cleaned URLs of the current request. You can also check if the current request is running in "preview" mode.
How to reference UmbracoContext
If you are using Views or Partial View Macros you can reference the UmbracoContext with the syntax: @UmbracoContext
If you need an UmbracoContext
in your own controllers, you need to inject an IUmbracoContextAccessor
.
The following is an example of how to get access to the UmbracoContext
in a controller:
UmbracoContext is registered with a scoped lifetime. See the Microsoft documentation for more information. A service scope is created for each request, which means you can resolve an instance directly in a controller.
Last updated