MVC 4 deployed to IIS 8 Page can't be Displayed - asp.net-mvc

I am trying to deploy a MVC 4 application to IIS 8 on Windows Server 2012.
I am copying the files to the server by using Publish > File System.
I have created a new web site in IIS on the server, pointed this to the correct directory, but when trying to view the site I see 'This page can’t be displayed'.
I have never deployed an MVC application before, so may have missed something very simple.
After spending a lot of time searching on the Web, I have:
Ensured the correct version of .NET (4.0) is installed, and is selected within a new Application Pool created specifically for my app
Disabled Directory Browsing
Ensured the System.Web.MVC.dll is copied into the Bin folder
Added the following to web.config:
Below:
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="managedHandler" />
</modules>
I am very grateful for any help or suggestions!
Martin

Oh dear...it looks like the problem was caused by my using Port 110 in the web site bindings. I think this is a reserved Port.
Hope some of the bullets above help someone else anyway.

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 "A default document is not configured " error when deploying ASP.NET MVC application on IIS 7.5

Developing an ASp.NET MVC 5 application. Runs without an issue on the development machine (Windows 7 x86). When I tried to deploy it on IIS 7.5 (Win Server 2008 R2 64 bit) I got 3 errors:
Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
I fixed this issue by removing targetFramework="4.5" from
<compilation debug="true" targetFramework="4.5">
The tag contains an invalid value for the 'culture' attribute.
I don't know why but compliant was about the following entry:
<globalization enableClientBasedCulture="true" culture="az-Latn" uiCulture="az-Latn" />
After removing culture="az-Latn" uiCulture="az-Latn" this problem also got solved. But I don't think this is a proper way of solving that, so it'd be good to know the right solution.
Now the third error is the one that's taken all my day. After solving the above two problems now I get the error in the image:
The best solution that seems to work for almost everybody is to add the following entry:
<modules runAllManagedModulesForAllRequests="true" />
But I already have it in the config file. IIS was missing URLRewrite module so I installed it manually.(Don't know if this has anything to do with it though). Didn't help. Enabled 32 bit Applications. Didn't help. What else should I try?
There are two possible solutions
Make sure the application pool that is running your site is set to version 4. It's likely defaulted to v2 which will give you all the errors you mentioned in the question.
Re-register your framework with this command:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i
I'd also revert those changes you have made (e.g. put the targetFramework attribute back in)

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?

Resources