简体   繁体   中英

Accessing Umbraco.TypedContentAtRoot() in another assembly

I'm trying to generate an xml sitemap for published Umbraco content . Ideally I'd like to access UmbracoHelper.TypedContentAtRoot() or something similar that gives easy access to published items. I need to access it outside the web solution, inside a supporting assembly where I'm generating xml sitemaps and sitemap index for dynamic content outside the direct control of Umbraco.

Any ideas about the easiest way to go about this? I've tried referencing various Umbraco assemblies and digging into what's readily available but haven't found anything immediately useful yet.

I have stumbled across

UmbracoContext.Current.Application.Services.ContentService.GetRootContent()

but this seems to require a much deeper understanding about how Umbraco content works under the covers in order to drill down to extract published content for me to index.

Can anyone point me in the right direction? Thanks in advance!

Assuming the DLL you are creating is going to be using IN the umbraco site, you will be able to access UmbracoContent.Current in your classes, as long as you've got a reference to the Umbraco.Core package, as Mivaweb states.

If on the other hand you want to access the UmbracoContext from a completely unrelated external application (say an executable file), then that it MUCH harder to do. A few people have got it sort of working, but it's a bit flakey. Usually in this case, you're better off adding some kind of WebAPI controller action that you can call via HTTP from your executable file, so you have full access to Umbraco on the site.

Update:

If you just want to access the typed content, you can get at it by using:

UmbracoContext.Current.ContentCache

This will allow you to do stuff like:

UmbracoContext.Current.ContentCache.GetAtRoot();

Which will get you all of the root content of the cache.

If you have a seperated project where you would like to do Umbraco stuff then go to the nuget package manager and install Umbraco.Core .

This will install only the necessary Umbraco dll's that you then can use.

Then you just need to include the namespace and you are ready to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM