Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Sitecore "Site" data from web.config in WCF

I understand the issues with WCF and Sitecore because Sitecore.Context would not be available to the WCF request.

But all I'm really looking to do is pass in a site name, and have WCF return some of the attributes of that "site" node from the "sites" section in the web.config.

For example, in the code below I have a site name of "mysitename" for the website "www.mysite.com". How could I programmically get the site's hostname from the web.config?

<sites>
   <site name="mysitename" hostName="www.mysite.com" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="100MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />
</sites>

I don't care if it uses prebuilt sitecore functions, or just .net code that is able to read this section of the web.config. Any feedback would help, thanks.

like image 323
adam Avatar asked Dec 12 '22 14:12

adam


1 Answers

You should be able to use something like:

var site = Sitecore.Configuration.Factory.GetSite(sitename);

The returned object is supposed to contain the site attributes from the config definition. Don't have Sitecore at my machine right now, so can't check exactly, but you can give it a quick try.

like image 105
Yan Sklyarenko Avatar answered Dec 23 '22 01:12

Yan Sklyarenko