ASP.net MVC deployment to IIS7 - asp.net-mvc

I'm trying to deploy a MVC application to a news Server, I have .net framework 4 and ASP.net MVC2 installed. My app pool is assigned to .net 4, integrated mode. But for some reason, the routing is not happening properly. I am getting a 404 error on links and not properly routed to the controller. What am i missing here? Is it might be order of installation of .net framework and IIS?

Your app is probably compiled against .Net Framework Version 2.0. Change your app pool to 2.0 and see if it helps.

Try this :
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
Or try to debug routing

So, if you got a 404 error that is because the global.asax is not being executed.
Check out if the IIS is configured to "Check if the Directory/File exists", cause the IIS is default configured to check first if the request exists on the server ... MVC doesn't use the 'real' path, per se.
Hope it helps ;)
EDIT
Try to log something at the time the routing is working ... I mean when the Route inside the global asax is called and check out if the mapping is called...

Related

Host MVC application in an existing site

I am already running a site where there are webforms and classic asp running concurrently. Now I have created a new project with MVC and trying to upload it to the site. I have published it in my local and uploaded files to site. But when I am trying to ping the url if says 404(file not found).
In order to get exact problem please add the following to your web.config under
<system.web>
<customErrors mode="Off" />
...
Then come back with your problem.

Getting 404 error on MVC web-site

I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully configured to run it as well, for local testing.
However, whenever I try and navigate to a page running in IIS7, I get a 404 error.
I have checked the following things:
There is no corresponding 404 log entry in IIS logs.
Actually, there are 404 entries in the IIS log.
The application pool for the web-site is set to use the Integrated pipeline.
The "customErrors" mode is set to off.
.NET 3.5 SP1 is installed
ASP.NET MVC 2 is installed
I've used MVC Diagnostics to confirm all MVC DLLs are being found.
ASP.NET is enabled in IIS, which we've demonstrated by running the MVC Diagnostics page.
KB 2023146 did highlight that HTTP Redirection was off, so we've turned it on, but no joy.
EDIT
Ok, so we've installed the world's simplest MVC application (the one which is created when you create a new MVC2 project in Visual Studio), and we are still getting 404s on any page we try and access - e.g.
<my_server>/Home/About will generate a 404.
Any ideas will be greatly appreciated!
This is quite often caused by the following missing from the web.config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
Do you have a problem with just 1 page or the whole site is not working?
A) 1 page
You can use RouteDebugger to verify if the route is matched correctly
B) Whole site
I assume you're using Windows Server - check if ASP.NET is enabled in IIS - it's disabled by default, I believe.
You can use MvcDiagnostics page to check if all dlls are deployed properly.
Are you running in IIS7 integrated mode? Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6)
Make sure your Web.config tag is configured correctly.
We finally nailed this issue by exporting the IIS configuration of a working server, and comparing it to ours.
It was a really obscure setting which had been changed from the default.
IIS ROOT → request Filtering → Filename Extensions Tab → Edit Feature Settings → Allow unlisted file name extensions
This should be ticked.
This can be set at the IIS level, or the site-level.
Glad that fixed your problem. Others researching this issue should take note of the extensionless URL hotfix: http://support.microsoft.com/kb/980368
If none of the other solutions here solved your issue, check that you have the
Global.asax
file in your website. This solved the issue for me.
Checkout if KB 2023146 applies to your scenario. Also try requesting directly a controller action: /yoursitename/home/index
Apparently this can have many different causes.
For us, the problem was that the DNS entry was configured for two IP addresses, but the IIS configuration would only listen to one of them. So we got unpredictable results, sometimes it would work, sometimes a few files (css, etc) would not load, and sometimes the whole page would not load.
For me it was all about installing .NET Framework 4.6.1 on the server (my app was targeting that version)
You'll also get this if your bindings aren't correct. If you don't have www or a subdomain it'll return a 404.
I had this problem when running my MVC4 site with an app pool set to ASP.NET 4.0 and the Classic pipeline, even though the extension handlers were set in my web.config and were showing correctly in IIS. The site worked in Integrated Pipeline so I knew it was a configuration issue, but I couldn't nail it down. I finally found that ASP.NET 4 was disabled for the server in the ISAPI and CGI Restrictions settings. I enabled ASP.NET 4.0 and it worked.
In addition to checking if you're running in integrated pipeline mode, make sure your application pool is set to use .NET! I recently ran into this problem, and when I went in to check the app pool settings, I found that somehow it had been set to "No Managed Code." Whoops!
My Hosting company fixed this for me by doing this (I removed the original password value of course).
<system.webServer>
<security>
<authentication>
<anonymousAuthentication password="<password>" />
</authentication>
</security>
</system.webServer>
Typically I encounter this issue when there is a Routing problem. I compare a working vs non-working to resolve it.
Today however I accidentially created a Virtual Directory in IIS.
It has to be an Application, right click on the Virtual Directory (with a folder icon) -> Convert to Application:
Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.
<system.webServer> <!-- Rather do NOT use this -->
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Instead add the MVC routing module
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>

ASP.NET MVC application when deployed to IIS 7 in integrated mode using NHibernate data will not load

We have built an ASP.NET MVC application which utilizes NHibernate, the MVCContrib version of StructureMap, and an onion architecture as outlined by Jeffery Palermo in ASP.NET MVC in Action. This application works well when running locally from Visual Studio 2008.
The Index action on our Home controller loads a view which immediately pulls data from the database utilizing the tools as outlined above. When running on IIS 6 or in Classic Mode on IIS 7 this section of the page loads data. Of course in both of these modes 404 File Not Found errors abound. Unfortunately, when running under IIS 7 Integrated mode no data loads and a simple error message Sorry, an error occurred while processing your request is displayed where the data should be rendered. Other page elements like CSS and images are loaded. Is there an IIS 7 setting we have missed? Is there something I should be looking for in the web.config?
Edit
Changed the customErrors mode setting in the web.config to off. Not sure if this is an ASP.NET MVC or IIS 7 thing but am now seeing a standard error screen on the pages that used to display the sorry error message. I am getting an unhandled exception of NullReferenceException: Object reference not set to an instance of an object. Looking at the stack this appears to be occurring when trying to get data. What would be the difference between IIS 7 Classic Mode / IIS 6 and IIS 7 Integrated mode that would cause this issue?
Edit 2
After some Googling this morning came across a post MVC + Sharp + IIS7 + NHibernate which seems like it would solve the problem. The post is from June '09 has something changed in the time since then that I don't have to drop back to classic mode?
After thinking about what was going on and realizing that issue probably had something to do with NHibernate I refined some of my Google searches and found a post HttpModule and HttpHandler sections in IIS 7 web.config files. This reminded me that NHibernate requires an httpModules entry.
<system.web>
<httpModules>
<add name="StartupModule" type="Infrastructure.NHibernateModule,
Infrastructure, Version=1.0.0.0, Culture=neutral"/>
</httpModules>
</system.web>
Because of the way that IIS 7 in integrated mode works I had to add the following to the modules section of system.webServer.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<add name="StartupModule" type="Infrastructure.NHibernateModule,
Infrastructure, Version=1.0.0.0, Culture=neutral" />
</modules>
</system.webServer>
Because I needed to have both the modules work in both system.web and system.webServer I added the validation section to the system.webServer.

"Resource not found" error while accessing elmah.axd in ASP.NET MVC project

My ASP.NET MVC application is within a folder called Stuff within IIS 6.0 webroot folder. So I access my pages as http://localhost/Stuff/Posts. I had EMLAH working while I was using the in-built webserver of Visual Studio. Now when I access http://localhost/Stuff/elmah.axd, I get resource not found error. Can anyone point my mistake here! Here is config file entry,
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> //Handler
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/> //Module
Working with IIS7 I found I needed both sections of the web.config populated (system.web AND system.webServer) - see Elmah not working with asp.net site.
Perhaps this is related.
Have you added an ignore *.axd routes in global.asax?
For Elmah, we need to differentiate between two things:
First the http modules doing all the work of error logging, emailing...etc.
Second, the http handlers, displaying the error log page and other pages (rss...etc.)
I was having the same problem of 404 resource not found because I have a weird setup!
on my development machine, (windows 7, iis 7 ) elmah was working like a charm because the application pool was working in the integrated pipeline mode. In the production machine, however, the application was using the managed pipeline and I tried all my best to make elmah work but it was all useless...
I then got the idea of displaying the UI (error log page, rss, error detail,...) using regular aspx pages.
I downloaded the source code, made some changes (sorry Atif, I was forced to do this because I needed the quickest solution) and then in my application , I created a folder under which I created regular aspx pages which inherits from Elmah defined pages.
The page only contains one line (ex: for the detail page: <%# Page Language="C#" Inherits ="Elmah.ErrorDetailPage"%>)
Now, I was able to run Elmah regardless of IIS 6/7 and it is working like a charm.. and It saved me from a big headache of correctly configuring http handlers and troubleshooting its work! additionally, configuring security is much simpler!
I don't know if the community is interested in this solution (If so, I am ready to post my full changes).
Hope that this gives you an idea on how to solve the problem in an alternative way (and if you need the modified dll with complete instructions on how to use it, just tell me!)
In the application pool settings in IIS set Managed Pipelin Mode to Classic if you don't want to change code or the web.config file. Your axd.s will then work as before.
Can you post the rest of your web.config?
Or, if you're comfortable enough, can you just ensure that the httpHandlers and httpModules (NOT handlers and modules) sections are filled in properly in the web.config?

How to make ASP.NET MVC work in IIS 6?

I have installed .NET Framework 3.5 SP1 and ASP.NET MVC CTP in a Windows Server 2003 R2 box, but my ASP.NET MVC site still doesn't work on that server. I was searching the internet and IIS for a solution and I noted that I can't choose other .NET Framework version besides 2.0 for my virtual directories. I'm almost sure if I correct this I can make my site work there.
Currently the main "/" URL answers with:
Directory Listing Denied
This Virtual Directory does not allow contents to be listed.
And the "/Default.aspx" URL answers with:
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: Section or group name 'system.web.extensions' is already defined.
Phil Haack has a pretty good writeup here
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
I had the similar issue.
I recently upgraded my server to support .net framework 4.0.
Converted my application to support .net fx 4.0.
Deployed the application on sever and trying to test .. I get "HTTP Error 404 - File or directory not found"
Solution
Open IIS Manager, expand the master server node (i.e, the Servername node), and then select the Web service extensions node.
In the right pane of IIS Manager, right-click the extension "ASP.NET v4.0.*".
Click the Allow button.
Besides Jason's answer, the common things to look for is:
Enable Wildcard mapping and point it to the aspnet assembly Phil mentions in Jason's link.
The /default.aspx error you are getting seems to be a web.config configuration error. At the very top of your web.config, look for:
<sectionGroup name="system.web.extensions"
Most likely it is defined twice. You only need the reference for the RC build you have. If you need the exact RC references, create a new ASP.NET MVC Web Project in a temp folder. And then grab the web.config from it.
-E
I also encountered this problem, in my case the solution was to uninstall the ASP.NET MVC Beta.
The application I was trying to get working had the version 1 MVC dlls bin deployed and once the Beta was uninstalled it all worked fine.
Similar issue: We tried to install an MVC4/.NET 4 app on an IIS6 box, set up everything as described, and got same error:
Directory Listing Denied
This Virtual Directory does not allow contents to be listed.
For us, the final fix was to add the UrlRoutingModule to the web.config:
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Which makes sense, but I don't know why we needed to explicitly add it and others didn't. (We are running in a directory under Sharepoint, maybe related...)

Resources