Here’s a simple way to create a dynamic Sitecore MVC robots.txt.
controller = "Robots",
action = "RobotsText"
2. Create a RobotsController
public class RobotsController : Controller
public FileContentResult RobotsText()
var contentBuilder = new StringBuilder();
return File(Encoding.UTF8.GetBytes(contentBuilder.ToString()), "text/plain");
private bool IsProduction
return (ConfigurationManager.AppSettings["IsProduction"] ?? "false") == "true";
3. Add /robots.txt to IgnoreUrlPrefixes setting in Sitecore.config
4. Ensure <modules runAllManagedModulesForAllRequests=”true”> is set to true within web.config.
If you are planning on using DI on your Sitecore 7.2 and later projects, you should be aware that Sitecore has itself started using MVC in some of it’s features. For example, if on an image field you click “Browse”, then “Upload”, this diaglog window will call the URL /api/sitecore/Media/Upload?sc_database=master which is an MVC route.
The issue is, if you have set the Controller Factory of your application to your own (this was done when using a Castle Windsor implementation) then you need to ensure you have registered the instances of IController within the Sitecore DLLs as well as your own. The DLLs you need to register are Sitecore.Speak.Client, Sitecore.Mvc and Sitecore.Mvc.DeviceSimulator. For example, in Castle Windsor you would need to add something like the following to your Installer which registers your controllers:
For further reading, look at Sitecore support ticket #429145
In a Sitecore instance that contains multiple sites, you may have found that links between different sites can result in incorrect URLs.
For example, suppose we have the following Sitecore structure:
- Site A (www.site-a.com)
- Site B (www.site-b.com)
Typically, a link from anywhere on Site A to Page B might result in a URL like “www.site-a.com/sitecore/site-b/page-b”, rather than the expected “www.site-b.com/page-b”.
There are a number of things you need to get right in order for this to work properly:
- The SiteResolving property needs to be set to true on the UrlOptions when calling LinkProvider.GetItemUrl().
There is a bug in that the Sitecore config setting (Rendering.SiteResolving) is never used to set this property automatically. This can be easily fixed by extending the LinkProvider with a few lines of code.
- Site definitions must have both hostName and targetHostName attributes set in order for site resolving to work (even if the sites in question all use the same hostnames)
If you want language to be preserved correctly across cross-site links then also:
- The Rendering.SiteResolvingMatchCurrentLanguage setting must be set to true
- The casing of the language names must be the same between the definitions in the Sitecore tree and the language attributes on the site site definitions, as a case-sensitive match is performed.
Some relevant articles:
When you are on the site in question:
- Left nav -> Site Contents
- Settings (on the right)
- People and groups
There is an easy way to keep tabs about what code is on each environment. There is a good MSBuild project which provides a set of useful additional MSBuild tasks:
To reference the extra tasks, you will need to make sure you have referenced the MSBuild Community Tasks Project DLL. The tasks of interest are GitVersion and GitBranch which will provide details of the SHA and branch that is being deployed. The following target is what you need to get started:
<Output TaskParameter="CommitHash" PropertyName="GitDeployedCommitHash" />
<Output TaskParameter="Branch" PropertyName="GitDeployedBranch" />
<GitVersionInformationLine Include="Deployment Date: $([System.DateTime]::Now)" />
<GitVersionInformationLine Include="Deployed by: $(USERNAME)" />
<GitVersionInformationLine Include="Git Branch: $(GitDeployedBranch)" />
<GitVersionInformationLine Include="Git Version: $(GitDeployedCommitHash)" />
This will generate a file to App_Config/__DeployInfo which will look something like:
Deployment Date: 22/12/2014 17:02:11
Deployed by: Mr Deployer
Git Branch: sprint
Git Version: b4bc2b4
Similar functionality could be added for Mercurial but isn’t included in this project, the following could be useful: https://msbuildhg.codeplex.com/documentation
If you need to log to a database instead of a text file, you can use Log4Net to do it by just changing some config: http://sitecoreblog.alexshyba.com/2010/07/sitecore-logging-write-it-to-sql.html
If you want to only log a small number of things to the database (but still log everything else to the existing log), then instead of adding the sql adonet appender to the main root logger in the config, create a new logger node and add the sql ado appender to that. Eg:
<logger name=”PublishLog” additivity=”false”>
Then when logging, explicitly use this logger using the Sitecore Logger Factory. Eg: “Sitecore.Diagnostics.LoggerFactory.GetLogger(“PublishLog”)”
Make sure you test with both your own and another account. I was caught out by just testing with my own account, the same one used to setup the app within https://developers.facebook.com/apps
For instructions on how to set up your application: http://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on
The missing step they don’t mention is you need to ‘activate’ the app for the public. This is done via the ‘Status & Review’ section of the app’s left nav. Remember to put a contact email in ‘Settings’ -> ‘Basic’
Download this: http://www.microsoft.com/en-gb/download/details.aspx?id=40772