Skip to main content

What should I do when on Azure Web Role I get "HTTP Error 401.2 - Unauthorized. You are not authorized to view this page due to invalid authentication headers"

This post is dedicated to a simple but annoying issue that can appear when you are developing a ASP.NET MVC Application.
When I run my web application on my local machine, directly from Visual Studio, my web sites works perfectly. When I deploy it on a Web Role I get "HTTP Error 401.2 - Unauthorized. You are not authorized to view this page due to invalid authentication headers"
The same problem can appears if you deploy on on-premises servers, but in general this problem pop-ups on Web Roles. Not because a web role is different (it has the same layers as a web server -OS and IIS), but because people that are working with cloud solutions forget about infrastructure layers.

If we are reading the error message we can identify some possible root causes. But basically it seems that the user that is trying to access the page is not authorized.
But why it is working on the development machine from Visual Studio? Simple, in general the developer is also the admin on the machine and he access the page as an administrator and has full access.
On the local machine this can be replicated easily if you deploy the web site on your local IIS and play a little with the user that access the web site.



If you will not set this value, the value that is set in IIS will be used by default. For web roles, by default IIS is 'closed', it means that it is not open for anonymous access and you need to specify if you want to allow anonymous users to access your website.
Based on what Visual Studio template you are using to create your web site, the value could be set by default to true or not.

To allow anonymous users to access your web site you need to do the following things in the configuration file (web.config):
<system.web>
     <authorization>
          <allow users="*" />
     </authorization>
</system.web>
...
<system.webServer>
     <security>
          <authorization>
               <add accessType="Allow" users="?" />
          </authorization>
     </security>
</system.webServer>
The above configuration disables all authentication mechanisms and allows anonymous users to access your site.

For HTTP error code 401.2 on Web Roles I observed that this is the most common problem.

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provided a too