Monday, March 31, 2014

Error 403, 403.14, 404 - After deploying ASP.NET MVC website on IIS 7, IIS 7.5

After deploying your ASP.NET MVC website on IIS 7 or IIS 7.5, you might face following errors while browsing your website:

  • 403.14 - Forbidden (The Web server is configured to not list the contents of this directory.)
  • 404 - Not Found (The resource you are looking for has been removed, had its name changed, or is temporarily unavailable)

Following are the possible causes/ fixes for this -
  • Make sure the Application pool targets correct version of .NET framework (i.e .NET Framework v4.0.30319 for .NET 4 and 4.5)
  • Make sure the Pipeline mode of IIS Application pool is "Integrated"
  • Check UrlRoutingModule-4.0 is added in the modules of that website.
  • (To do that, open list of added modules by clicking "Modules" against your website, and see if the module "UrlRoutingModule-4.0" is added or not). If not, then add a module by clicking "Add Managed Module" button, where select System.Web.Routing.UrlRoutingModule as a Module type, and give "UrlRoutingModule-4.0" as its name)
  • Make sure you have following element added in system.webServer section of website's web.config
<modules runAllManagedModulesForAllRequests="true"></modules> 

In most cases of 403.14, or 404 error, above are the possible causes and fixes. 

Tuesday, March 25, 2014

FIX: 'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage.Model'

I suddenly started receiving this error in one of my razor view. The error message was -
'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage<TModel>.Model'

This error is caused if you use "Model" instead of "model" in one or more lambda expressions (predicates) in your view.

Perform a case-sensitive search for "Model =>", and its very much possible that you may notice this in one or more lambda expressions,
For example,
@Html.EditorFor(Model => Model.BirthDate)
This should be actually, @Html.EditorFor(model => model.BirthDate)
Correcting this should fix the Model conflict error for you in your view.