Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi
I am trying to add a custom route for robots.txt following - https://our.umbraco.com/documentation/reference/routing/custom-routes#custom-routes-within-the-umbraco-pipeline
However as its a file path the UmbracoContext is null in v7 you could create your own context to solve this issue, this has been removed in v8.
How can I achieve this?
v7 code
protected override UmbracoContext GetUmbracoContext(RequestContext requestContext) { var ctx = base.GetUmbracoContext(requestContext); if (ctx != null) return ctx; var httpContext = requestContext.HttpContext; ctx = UmbracoContext.EnsureContext(httpContext, ApplicationContext, new WebSecurity(httpContext, ApplicationContext), UmbracoConfig.For.UmbracoSettings(), UrlProviderResolver.Current.Providers, false, false); return ctx; }
Hi ,
I believe you use the IUmbracoContextFactory to ensure the context.
So Ideally through Dependency Injection and then
var contextRefrence = umbracoContextFactory.EnsureUmbracoContext()
and at a push Umbraco.Web.Composing.Current.UmbracoContext
Umbraco.Web.Composing.Current.UmbracoContext
There are more details in this PR comment : https://github.com/umbraco/Umbraco-CMS/issues/4572#issuecomment-463595962
You'll want to resolve an IUmbracoContextFactory and call it's EnsureUmbracoContext() method
IUmbracoContextFactory
using (_umbracoContextFactory.EnsureUmbracoContext()) { // Do your thing }
Thanks both! (who gets the marked answer???)
For anyone who is trying to achieve the same result Callum has a package which you can use or view the source of :)
https://github.com/callumbwhyte/friendly-robots
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Using UmbracoVirtualNodeRouteHandler for routing robots.txt
Hi
I am trying to add a custom route for robots.txt following - https://our.umbraco.com/documentation/reference/routing/custom-routes#custom-routes-within-the-umbraco-pipeline
However as its a file path the UmbracoContext is null in v7 you could create your own context to solve this issue, this has been removed in v8.
How can I achieve this?
v7 code
Hi ,
I believe you use the IUmbracoContextFactory to ensure the context.
So Ideally through Dependency Injection and then
and at a push
Umbraco.Web.Composing.Current.UmbracoContext
There are more details in this PR comment : https://github.com/umbraco/Umbraco-CMS/issues/4572#issuecomment-463595962
You'll want to resolve an
IUmbracoContextFactory
and call it's EnsureUmbracoContext() methodThanks both! (who gets the marked answer???)
For anyone who is trying to achieve the same result Callum has a package which you can use or view the source of :)
https://github.com/callumbwhyte/friendly-robots
is working on a reply...