ASP.NET Error Messages

70 comments

The following error messages are those typically encountered due to site configuration and other general conditions that are not obvious compilation or runtime errors. As our standard platform is ASP.NET MVC 2, many of the solutions assume that is the platform.

 

If you get an IIS error that you can't find it here, look in this Microsoft KB article: http://support.microsoft.com/kb/943891


"The page cannot be displayed because an internal server error has occurred" 

As text text by itself, no other html or text in the response


I just got this error and it was caused by a duplicate static content MIME type in the web.config


This error was being returned only on static files - eg images, css, js files were all saying this error.


The way to debug this is to look in web config under static content. Here we have a json file extension loaded. This was required on IIS7 but will kill the app if used on IIS8 because json is now pre-loaded at the server level.


   


So solution is to remove any of these mimeType entries one at a time to confirm which are needed and which kill your app!




MasterPage cannot be applied to this page because the control collection is read-only. If the page contains code blocks, make sure they are placed inside content controls (i.e. )


This happens in MVC when you forget to include the asp:Content tag in your view. (This should map to a ContentPlaceholder in the master page)



A potentially dangerous Request.Form value was detected from the client...

 

This happens in .net 4 when you post html in a form tag - e.g. rich text editor like tinymce.

 

Solution:

When you upgrade a site from .net 3.5 to .net 4 and the web.config gets rewritten for you by visual studio, you may need to add the following to the new web.config.

requestValidationMode="2.0" />

Server Error

500 - Internal server error.

There is a problem with the resource you are looking for, and it cannot be displayed.

 

This is a standard billy basic IIS error which is not normally displayed unless there is something wrong with our error handler. It means errors are not being caught at the global.asax level which may mean the application is not yet running. It can also occur if ASP.NET cannot parse the web.config (you would think it would display a parsing error - but no).

 

Solution:

Check the web.config is valid. Does it run on local? Is it different on local? 

 


Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
Source Error: 

Line 14: Line 15:  Line 16:  Line 17:  Line 18: 

 

 

Your web.config is for a .NET 4 site but the app pool is running on an earlier version (usually .NET framework version 2 which runs all versions up to 3.5 but will not run 4). 

 

Solution:

Change the App Pool's framework version must be set to .NET v4. If this is not an option, you will need to install .NET 4 runtime (download it from microsoft directly on to the server if possible as it is a big download).

 


HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.

 

This could occur if the app pool is set incorrectly.

 

Solution 1:

To run ASP.NET MVC the app pool must be set to "integrated" pipeline mode .NET v4.

 

Solution 2:

MVC may not be not registered with IIS under .NET 4 app pools. If you go to a folder that exists and has a default.aspx page, you will instead see this message:

Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

 

To fix, go into windows directory subfolder %windir%\Microsoft.NET\Framework\v4.0.XXXX and run aspnet_regiis.exe -i

 

Also: Make sure you have a global.asax (and .cs)

 

NOTE: Directory Listing Denied error (in IIS6)

IIS6 does not have integrated pipeline mode therefore you will need to add a new application pool and choose Use existing application pool as template(choose the ASP.NETV4).

In the Properties of the site make sure the site set to .net 4  in the ASP.NET and ensure the default default document is set to a .Net page in the Documents tab.

 

A possible alternative solution is to add a wildcard mapping to ASP.NET runtime (this is the easiest solution if it works).

 


Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'Site.MvcApplication'.
Source Error:

Line 1: <@ application="" codebehind="Global.asax.cs" inherits="Site.MvcApplication" language="C#"> 

 

Solution 0:

Embarrassingly simple - you have just checked the files out of subversion and have not yet hit "Build". 

 

Solution 1:

The problem may be it is confused about whether it is an MVC 2 application or an MVC 3 application. You need to remove the References to System.Web.Mvc, System.Web.Abstractions and System.Web.Routing in the Site project and then add them back again, by clicking Add Reference, Browse and locate the DLLs in the BIN folder of the project. (Note: do not remove/add references in the SavvyCore or SavvyMVC projects) 

 

Solution 2:

Otherwise, it could be that the application simply can't compile. Normally the app will usually still run when there is a compile error because the old DLL will still exist, but this may be trying to compile global.asax or any aspx page (both of which sit outside of the DLL) and something used by that file/class is not able to compile. For example, if you have two namespaces with the same name (eg Models and Site.Models) the wrong one might be trying to compile.

 

 


Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage'.
Source Error:

 Line 1:  <%@ inherits="System.Web.Mvc.ViewPage<Site.Controllers.SecurityController.LoginFormViewData>" masterpagefile="~/Areas/Admin/admin-no-form.master">

 

Solution:

Add the following attributes to your tag in the web.config. These attribute values differ for each MVC version.

 

MVC version 2:

 


          pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

          pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

          userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">


 

MVC version 3:

 

<pages

        validateRequest="false"

        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

     

       

     

   

 


 


 

Validation of viewstate MAC failed

 

If you get this all the time:

- check to make sure you only have one FORM tag on the page

 

- if you are using Server.Transfer or Url Rewriting there is a high likelyhood that your form tag's action attribute does not match the Request.RawUrl. We get around this normally with an Adapter called FormRewriter that overrides the action attribute to be RawUrl. To fix it you should do the following:

Form.Attribute = "formaction.aspx" // the correct action

HttpContext.Current.Items["ActionAlreadyWritten"] = true;  // the adapter checks this and only overrides the form's action if it is null

 

If intermittent:

- make sure you are running .NET 3.5 SP1 

Full details here:

http://blogs.msdn.com/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx 

 

- You MUST specify machineKey  in web config

This also applies to the MVC AntiForgeryToken attribute, which uses the machinekey for encryption. If you don't specify a machinekey in the web.config (see here), one is automatically generated for you by ASP.NET (full description).

If the ASP.NET application is restarted (e.g. do an iisreset), the AntiForgeryToken within the browser cookie will still be encrypted with an old machine key, hence why it crashes with the above error.

So you should always specify a machinekey in your web.config when using MVC, e.g.


   
                   validationKey="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B"         
            decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F"
            validation="SHA1"
            decryption="AES"
        />
    ...

 


Attempted to access an unloaded AppDomain.

 

This error occurs when you try to compile/build your website.

 

Solution:

Close visual studio, delete yoursolution.suo file, open visual studio.

 


HTTP Error 500.21 - Internal Server Error

Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

 

Solution:

You may have upgraded .NET version to version 4, and it needs to be registered with IIS. Typically this is supposed to happen automatically if you run the proper installer. To fix, go into windows directory subfolder %windir%\Microsoft.NET\Framework\v4.0.XXXX and run aspnet_regiis.exe -i

 


The configSource file 'Web_ConnectionStrings.config' is also used in a parent, this is not allowed 

 

Problem:

In IIS you have the application URL mapped to its own parent. I somehow accidentally added an application with a blank Physical Path , thereby pointing to the root of the default website (ie localhost). This is from my applicationHost.config file (which is used by IIS).

       
           
               
                   
               

 

Found this explanation on the web:

I was accessing  http://localhost/MyProject/  ... the error stemmed from  http://localhost/ also mapping to the exact same location as http://localhost/MyProject/ , thereby causing localhost (the "parent") to be using the same configSource location as its child MyProject.  when I accessed http://localhost/MyProject/ , it caused this error. but when going to http://localhost/ everything works just fine

 

Solution:

Click on Default Web Site, click on Advanced Settings. Change the Physical Path to the proper place (eg c:\dev or c:\webroot).

 

Alternatively,  look at your applicationHost.config file in C:\Windows\System32\inetsrv\config and confirm this is the problem. It seems to start with some zero bytes which prevents it being edited in most text editors - you can edit it by comparing it to something else using Beyond Compare. Change the Physical Path 

 


HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.




Problem:

You are trying to run a .net 3.5 web config but this will not run under .net 4.0.

 

Solution:

Your app pool is set to .net 4.0 but you need to change the app pool to 2.0. (Confusing, but .net 3.5 actually runs on 2.0 runtime)

 

 

Server Error in '/' Application. (IIS 6)


Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".

     

 


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.

 

Problem:

Website in set to the wrong version of .net. this can happen on IIS 6.

 

Solution:

Your app pool is  not set to .net 4.0 so change it to 4 in the Properties of the site under the ASP.NET tab.

 


HTTP Error 404.17 - Not Found

The requested content appears to be script and will not be served by the static file handler.

 

Problem:

This can occur in a when browsing an URL ending in ".aspx". The handler mappings are not correctly set up. This could be because the app pool is set to a different version of .net, different bitness or different pipeline mode than the handler mappings are set up to receive. Handler mappings will direct an ASPX page to a handler such as "PageHandlerFactory-ISAPI-4.0_32bit". This will only work if you have the app pool set to .net 32bit or you set up additional handler mappings.

 

Solution:

To install the .net handler mappings or .net 4 handler mappings, run cmd, cd into windows directory subfolder %windir%\Microsoft.NET\Framework64\v2.XXXX and/or %windir%\Microsoft.NET\Framework64\v4.XXXX and run aspnet_regiis.exe -i

If this does not solve it, see http://support.microsoft.com/kb/2019689 to understand handler mapping preconditions fully.



Could not load file or assembly ... An attempt was made to load a program with an incorrect format (System.BadImageFormatException)


Problem:

It's very likely to be a 32-bit / 64-bit conflict. 


Solution:

Go to Project => Properties => Build and set the "Platform Target" to "Any CPU".

If you only have a DLL file or a rebuild is not possible for any reason, make sure the app pool is set to enable 32 bit applications. 


 


HTTP 417 “Expectation Failed.”

 

Problem:

System.Net.HttpWebRequest adds the header 'HTTP header "Expect: 100-Continue"' to every request unless you explicitly ask it not to.


Solution:

Set this static property to false:


System.Net.ServicePointManager.Expect100Continue = false;

Comments


Leave a Comment