MVC2 Areas and Controller 404 - asp.net-mvc-2

My project namespace is
MyProject.MVC
So my controllers, which are segregated into Areas, are in this namespace:
MyProject.MVC.Areas.AreaName
But when I try to access a controller action in this namespace, I get a 404 error:
http://MySite/AreaName/Action/View
If I "remove" the MVC portion from the namespace on my controllers, everything works correctly.
MyProject.Areas.AreaName
Could I have things wired incorrectly or is this an issues with MVC2 Areas?

MyProject.Areas.AreaName is the default namespace used when you start a new project.
I think you have changed your namespaces but forgot to do so on some places.
Try to search your whole solution for MyProject.Areas.AreaName and if you find one, replace it with your MyProject.MVC.Areas.AreaName.
For example look if your AreaRegistration is in the right namespace.
I'm working on a MVC2 project myself with even more complex namespaces and they work, so i think you have an error in your project.

Related

API Controller Routing in .NET 6 Doesn't Work Any More

I'm trying to create a standard WebAPI project in .NET 6. I notice that the standard ApiController route doesn't have the leading api route that I like to have. When I add it, the controller breaks. It doesn't give me a 404 (not found), it just gives me that index page that says that I have to enable javascript. I'm really at a loss at what I have to do to make my app work where I can put api at the start of my routes:
[Route("api/[controller]")]
I've tried adding it to the default controller route map in different combinations. I've tried adding the UseEndpoints method in the Program class. I'm just not sure what to differently in 6.
For those who want to "see my code", I'm just using the standard WebAPI project w/ React (NO Redux!).
Check the new setupProxy.js file image description inside the ClientApp folder, you need to configure the backend routes in the proxy config, I had a similar issue with the ASP.NET Core 6.0 with Angular project template, you can find more information here link 1 link 2

ASP.NET MVC2 IoC: Looking for an example using CastleWindsor container that works with minimum config

I am looking for an example of how to configure an ASP.NET MVC2 project to use CastleWindsor container to do IoC.
I keep running into problems setting it up, and for every problem there seems to be a solution on-line, but in the end I make so many changes and end up with such a verbose setup to get IoC working using CastleWindsor, that I thought it best to ask this question.
I am looking for the minimum configuration required in the Global.asax page, the Web.config, and if required, what other changes and extension classes are required.
I am not looking to inject into actionfilters at this stage, so just the basics. Preferably not using XML files, but doing it in .NET programatically.
Thank you in advance...
This is as basic as it gets:
Start a MVC2 project from VS2010
Download MvcContrib for MVC2 (the one that says "extra binaries")
In your project, add a reference to (all these DLLs are included in MvcContrib):
Castle.Core.dll
Castle.DynamicProxy2.dll
Castle.MicroKernel.dll
Castle.Windsor.dll
MvcContrib.dll
MvcContrib.Castle.dll
In your Application_Start(), add these lines (and whatever namespaces are needed):
var container = new WindsorContainer();
container.RegisterControllers(typeof(HomeController).Assembly);
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

zend framework controller not found?

I downloaded the latest version of Zend framework, added a controller and I
can not get it to load.. Here is what I did:
C:\zend\Apache2\htdocs>zf create project myproject
Creating project at C:/zend/Apache2/htdocs/myproject
Note: This command created a web project, for more information setting up your V
HOST, please see docs/README
C:\zend\Apache2\htdocs>cd myproject
C:\zend\Apache2\htdocs\myproject>zf create controller mycontroller
Note: The canonical controller name that is used with other providers is "Mycont
roller"; not "mycontroller" as supplied
Creating a controller at C:\zend\Apache2\htdocs\myproject/application/controller
s/MycontrollerController.php
Creating an index action method in controller Mycontroller
Creating a view script for the index action method at C:\zend\Apache2\htdocs\myp
roject/application/views/scripts/mycontroller/index.phtml
Creating a controller test file at C:\zend\Apache2\htdocs\myproject/tests/applic
ation/controllers/MycontrollerControllerTest.php
Updating project profile 'C:\zend\Apache2\htdocs\myproject/.zfproject.xml'
C:\zend\Apache2\htdocs\myproject>
Then I tried to hit the controller from the browser..
http://localhost/myproject/public/mycontroller/
and I get the error: Not Found
The requested URL /myproject/public/mycontroller/ was not found on this server.
I have no idea how to resolve this, and I'm sort of shocked I'm having problems
with the Zend Server.
Dooh.. Actually the problem was quite simple.. I forgot the mod_rewrite.. Strange Zend didn't turn it on by default.
Check out the Zend Quick Start. It looks like you don't have the document root setup properly. Your request should have been http://localhost/myproject/mycontroller or http://myproject/mycontroller - if setup properly.

Different controllers with the same name in two different areas results in a routing conflict

I have two areas:
ControlPanel and Patients.
Both have a controller called ProblemsController that are similar in name only. The desired results would be routes that yield /controlpanel/problems => MyApp.Areas.ControlPanel.Controllers.ProblemsController and /patients/problems => MyApp.Areas.Patients.Controllers.ProblemsController.
Each has routes configured like this:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"**Area Name Here**_default",
"**Area Name Here**/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
where *****Area Name Here***** is either ControlPanel or Patients.
When I go to /patients/problems/create (for example), I get a 404 where the routing error says: A public action method 'create' was not found on controller 'MyApp.Areas.ControlPanel.Controllers.ProblemsController'.
I'm not sure what I'm doing wrong.
Actually, it turns out the problem is with Autofac 2.1's AutofacControllerFactory. The routes are working correctly, but autofac is having a hard time finding the right controller.
For those that are using Autofac and MVC 2.0, Autofac 2.1 doesn't have support for areas. If your project is simple enough, Autofac may appear to work with areas, but it will start breaking down as your areas and controllers become more sophisticated.
The ticket for full Area support has been closed and the related code checked in, but from what I can tell it won't be released until 2.2. I'm going to try building from the trunk and I'll report back how it goes.
UPDATE
Yep, everything looks good using Autofac built from the trunk. Hopefully 2.2 will be officially released soon.
Have you tried using the overload with the namespaces parameter?
ASP.NET MVC 2 Preview 2: Areas duplicate controller problem

Deploying MVC2 application to IIS7.5 - Ninject asked to provide controllers for content files

I have an application that started life as an MVC (1.0) app in Visual Studio 2008 Sp1 with a bunch of Silverlight 3 projects as part of the site. Nothing fancy at all. Using Ninject for dependency injection (first version 2 beta, now the released version 2 with the MVC extensions).
With the release of .Net 4.0, VS2010, MVC2 etc., we decided to move the application to the newest platform. The conversion wizard in VS2010 apparently took care of everything, with one exception - it didn't change references to mvc1 to now point to mvc2, so I had to do that manually. Of course, this makes me think about other MVC2 things that could be missing from my app, that would be there if I did File -> New Project... But that is not the focus of this question.
When I deploy this application to the IIS 7.5 server (running on Win2008 R2 x64), the application as such works. However, images, scripts and other static content doesn't seem to exist. Of course they are there on disk on the server, but they don't show up in the client web browser.
I am fairly new to IIS, so the only trick I knew is to try to open the web page in a browser on the server, as that could give me more information. And here, finally, we meet our enemy. If I try to go directly to the URL of one of the images (http://server/Content/someimage.jpg for instance), I get the following error in the browser:
The IControllerFactory 'Ninject.Web.Mvc.NinjectControllerFactory' did not return a controller for a controller named 'Content'.
Aha. The web server tries to feed this request to MVC, who with its' default routing setup assumes Content to be a controller, and fails.
How can I get it to treat Content/ and Scripts/ (among others) as non-controllers and just pass through the static content? This of course works with Cassini on my developer machine, but as soon as I deploy, this problem hits.
I am using the last version of Ninject MVC 2 where the IoC tool should pass missing controllers to the base controller factory, but this has apparently not helped. I have also tried to add ignore routes for Content etc., but this apparently has no effect either. I am not even sure I am addressing the problem on the right level.
Does anyone know where to look to get this app going? I have full control of the web server so I can more or less do whatever I want to it, as long as it starts working.
Thanks!
I had a similar problem with StructureMap and favorite.ico what I ended up doing was to add a route to ignore that path.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("favicon.ico");
Keep in mind that I have absolutely no idea really but another thing that changed is the need for Default.aspx, also if you have any custom pages those would need to mapped. That's the only two problems I had with routing.
routes.RouteExistingFiles = false;
EDIT: I meant that the RouteExistingFiles should be false otherwise I get that exception in MVC2 :)
Turns out this was caused by some account settings - I was unaware of the IIS AppPool\sitename account automatically being created by IIS in Win2008 R2 server. After trying "everything", I came across this information, gave the proper rights, and stuff magically started working.
Pretty hard thing to debug, especially for someone (me) with very limited IIS experience.