ASP.NET MVC2: Can't find controller - asp.net-mvc

I have an MVC 2.0 web site that is using Areas. When I go to the default page (localhost/mywebsite/default.aspx), it correctly routes to the correct action in the correct controller and renders the default view correctly.
But on the page I have several Html.ActionLinks, and these do not seem to be able to find the Controller. When I click on the links in the page, I get a 404 error.
The URLs are what I expect: localhost/mywebsite/MyAreaName/Home/Index (for example). I've also tried localhost/mywebsite/Areas/MyAreaName/Home/Index, but this also gives me a 404.
How do I get the Controller to be recognized?

You probably don't have your IIS settings setup correctly to map the requests correctly.
Is IIS verify that you have set the "Wildcard application maps" to:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
And make sure you have the "Verify file exists" checkbox unchecked.
Walkthrough - read section "IIS6 Extension-less URLs"
(source: haacked.com)
More information with IIS 6 MVC setup
More IIS Info
EDIT: Since your using IIS 7, verify that it is running in integrated mode. If it is running in classic mode the mapping is NOT done automatically just like the way IIS6 works.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

You're using areas, have you registered the area routes?
ASP.NET MVC 2 Beta single-project Area registration getting HTTP 404

#Kelsey, I did have the app pool set correctly with integrated pipeline mode. But thanks for leading me down the correct path. I had the required config settings in a web.config in the Area, and not in the root of the web site, so the routing was never applied. I moved the config settings the the root level web.config and everything is working.
Thanks for your help, and Meff, thanks for all your ideas as well.

Related

IIS overriding handling of 404 and 500 http status codes in MVC

I'm using MVC 4 with IIS 7.5. I'm trying to handle 404, 500 and other codes with my own controller and view.
However, no matter what I try, IIS overrides my settings/code and injects it's own 404 (and so on) error pages. This happens locally on dev machine with IIS Express as well as production with IIS 7.5.
Here's a combination of all I've tried so far:
Used tag in web.config with redirect to my custom error view, no luck.
Provided custom error handling in Global.asax. It gets there (tried 404 and 500), it does call my custom controller and view, but at the end, IIS still wins and shows its page instead of my view.
By the way, I'm trying this will extensionless url as well as .html pages. How can I get IIS to leave it alone and allow MVC to take care of these errors.
I"m out of options at this point. Any advice would be appreciated.
You need to override how IIS handles the error status codes. This can be done by simply modifying the <system.webServer> section in your web.config.
<httpErrors existingResponse="PassThrough" />
Full information can be found on the IIS.NET site: http://www.iis.net/configreference/system.webserver/httperrors

MVC deployment in IIS 6 in win server 2003

Please help me how to deploy mvc3 application in IIS 6. I don't know how to set first page (start page in mvc) application. Which page I want to set first and hpw to set, I copied my full application from local machine to remote server.
Look here: http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/. You're not really setting a "default page" in MVC since everything is routed to controllers.
Try to access any of your action method/ page and see whether the MVC routing works for you.
To make the extensionless url work in IIS6, You need to enable wildcard mapping. Make sure you uncheck the "Verify file exist" option. Wildcard mapping brings some performance problems though. check the blog post by Phil explaining it.

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>

How do I get the site root to return the correct page w/ ASP.NET MVC + WebForms + ISS 6 Wildcard mapping?

Currently, I'm converting a web application from web forms to ASP.NET MVC. The project has been converted and IIS 6 is setup w/ wildcard mapping. I also have made one MVC view/controller that works just fine. There is one problem though. When accessing the the site root, the routing engine kicks in and redirects the user to the default controller, instead of the default page setup in IIS. Is there a way to have IIS use the default page, before the routing engine kicks in?
If not...
I have tried to have the default controller just redirect the user to the default page (LoginPage.aspx). That works except that web.config authorization seems to think that the path is not authorized, thus it redirects to path that looks like http://dev01/SampleWebApp/LoginPage.aspx?ReturnUrl=%2fSampleWebApp
If go to the default controller directly (http://dev01/SampleWebApp/default/) the user gets re-directed to the login page with the correct path.
So is there a way to get the site root to by pass web.config authorization and redirect to the login page w/o the ReturnUrl?
Any help is greatly appreciated.
Thanks,
Darren
at the top of the routes config in global.asax:
routes.IgnoreRoute("LoginPage.aspx");
or:
routes.IgnoreRoute("/");
haven't tried it, but one of those 2 options should work.
So the solution my problem was to use url mappings in the web.config under the system.web tag:
<urlMappings enabled="true">
<add url="~/" mappedUrl="~/LoginPage.aspx"/>
<add url="~" mappedUrl="~/LoginPage.aspx"/>
</urlMappings>
"~/" will re-direct the http://dev01/SampleWebApp/ path.
"~" will re-direct the http://dev01/SampleWebApp path.

ASP.NET MVC issue

I have a ASP.NET MVC app and when I run it, it loads my Index action on my HomeController
by default ok.
But when I put in this URl I get 404 - Not Found error
http://localhost/MyGoogleApp/Home/Index
This is the same for any action I put in in Home Controller.
Something fundamentally wrong, any ideas?
Malcolm
You probably have a configuration problem with URL mapping in IIS itself.
I haven't worked much with IIS7, but I think this is what you should check:
Managed pipeline mode should be 'Integrated'.
web.config should include system.webServer with all standard stuff new MVC project puts there (I can't check what exactly right now).

Resources