Configure 404 Errors in Azure with Umbraco

In Azure you will need to add a line to your web.config to allow the Umbraco 404 error page to work, otherwise your users will be greeted with the following message:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

The change you need to make in your web.config is as follows:

<configuration>
  ...
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
  ...
  </system.webServer>
  ...
</configuration>

Umbraco: An unexpected network error on Azure Web Apps

So i've had an ongoing issue with Umbraco sites randomly failing (500 Errors) in Azure when setup as Web Apps.

I have managed to find a solution for this, the Examine Index needs to be stored in the %temp% folder, otherwise the indexes get removed / corrupted everytime something in the bin folder changes.

The recorded error should be similar to below:

Exception type: IOException Exception message: An unexpected network error occurred. at Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, CacheDependency dependency) at Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) at Umbraco.Core.Cache.DeepCloneRuntimeCacheProvider.GetCacheItem(String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetCacheValues(Int32 id, Func2 func) at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetUmbracoMedia(Int32 id) at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetById(UmbracoContext umbracoContext, Boolean preview, Int32 nodeId) at Umbraco.Web.PublishedCache.ContextualPublishedCache1.GetById(Boolean preview, Int32 contentId) at Umbraco.Web.PublishedContentQuery.DocumentById(Int32 id, ContextualPublishedCache cache, Object ifNotFound) at Umbraco.Web.PublishedContentQuery.Media(Int32 id) at Umbraco.Web.UmbracoHelper.Media(String id)

The solution i have found for this, is pretty quick and easy to do, simply open the config/ExamineSettings.config and add the following on to the examine config lines:

useTempStorage="Sync"

Pretty simple fix :)

(You can see the Umbraco Pull Request here)

Geting PreValues from Umbraco Data Type

I thought i would share the solution to getting the pre values from a Data Type, as the documentation for this on the Umbraco website seems to have been removed.

The code below is an edited version of what worked for me (to remove the project details).

You will need to replace NAME or name with your values to make this work correctly, however it should point in the right direction.

 

Controller

[ChildActionOnly]
[ActionName("NAME")]
public ActionResult NAME()
{
    return PartialView("~/Views/Partials/NAME.cshtml", new MODELNAME{NAME = GetSelectListForNAME()});
}

        private SelectList GetSelectListForNAME()
        {
            var preValueDataType = Umbraco.DataTypeService.GetPreValuesCollectionByDataTypeId(1301); //Change Data Type ID
            var preValues = preValueDataType.PreValuesAsDictionary.Values.Where(pdv => pdv.Value != "0");

            var namesList = preValues.Select(preValue => new SelectListItem
                {
                    Value = preValue.Id.ToString(),
                    Text = preValue.Value
                })
                .ToList();
            return new SelectList(namesList);
        }

Model

public SelectList NAMES { get; set; }

public string NAME { get; set; }

Razor View

This will populate a drop down list

@Html.DropDownListFor(model => model.NAME, Model.NAMES.Items as List)

Recursivly Include In Visual Studio

When ever i build with Umbraco i find that i have to manually include files / folders into Visual Studio to be able to edit them with intellisense.

The is especially helpful when working with Views, to add the Views folder and all items under it recursively to Visual Studio just follow my tips below:

Unload your project by right clicking on your project name and clicking on Unload Project

Next right click your project name and click Edit PROJECTNAME.csproj

Once you have opened this file remove any lines containing the following:

<Content Include="Views

then when you have done that include the following line:

<Content Include="Views\**" />

 

Then just simply save the file, right click on your project name and then Reload Project.

All of your files under Views should now be included in your project and usable with intellisense.

Umbraco Build Error - New Installation From NuGet

One really annoying bug yet to be solved on a fresh install of Umbraco from NuGet in Visual Studio is the following build error:

CSC : warning AD0001: Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer' threw an exception of type 'System.TypeInitializationException' with message 'The type initializer for 'Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer`1' threw an exception.'.

This is really easily solved, 1 NuGet package needs updating to remove this issue, simply open Manage NuGet Packages go to the Installed tab and search for the following:

microsoft.codeanalysis.csharp

And them simply update to the latest version.

Hopefully they will roll this out as a fix eventually, I have raised this with them on their forums with no reply.