sitecoresitecore8.1

Sitecore MVC does not give error for .aspx pages


We are using Sitecore 8.1 with MVC format. We just discovered that if we have a link like: mywebsite.com/about or mywebsite.com/contact

If you write mywebsite.com/about.aspx it works as the page was there. Is this a desired functionality? If we don't want to have only the version without .aspx how can we do that? Is this possible?

EDIT: this is how the url's are being generated:

<linkManager defaultProvider="sitecore">
<providers>
  <clear />
  <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="always" languageLocation="filePath" lowercaseUrls="false" shortenUrls="true" useDisplayName="false" />
</providers>


Solution

  • This is Sitecore default behavior, but what you can do, is redirect any .aspx page to the correct URL, keep addAspxExtension="false" in sitecore Link Manager configuration, and add the following code to your main layout :

     string itemUrl = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item);
     if (itemUrl != Request.Path)
        {
            Response.Redirect(itemUrl);
        }