ASP.NET MVC2 Empty Project Not Loading - visual-studio-2010

My environment consists of Visual Studio 2010 and Windows 7 a few months ago I developed an MVC2 application with no problems however after trying to create a new project recently I received the error below.
I did find the link http://support.microsoft.com/kb/894670 but this is not relevant because I am not using IIS for testing, just F5 to get this working :)
Any ideas or help would be appreciated.
Server Error in '/' Application.
--------------------------------------------------------------------------------
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4927

The Empty MVC 2 template application does not define any controllers or views. When you create a new Empty MVC 2 application and immediately run it, you will see the error message you posted.
If you check the Global.asax file, you'll see that the project template automatically registers a default route specifying a default controller named "Home" and a default action named "Index".
To get this to run, right-click on the Controllers folder, then choose Add->Controller... Name the controller "HomeController". You can leave the check box to "Add action methods for Create, Update, Delete..." unchecked.
In the HomeController.cs file, right click in the Index() method and choose Add View...
Leave the View name as "Index", uncheck "Select master page", and then click Add.
In the Index view, you can enter some HTML and run the project; you should now see the page rendered by Index.aspx.
One thing I am not sure of is why your error message lists the .NET Framework version as 2.0. If you still have problems, check the target framework on your project properties.

Make sure that the routes are set properly and that you have default values for a controller and action. For example if you have the following route:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
Make sure that you have a HomeController with an Index action.

Related

Tutorial ASP.NET Core app not seen by localhost

Using MS Visual Studio 2022 on Windows 10 pro to build an ASP.NET Core MVC for the first time. When this tutorial (https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?view=aspnetcore-6.0&tabs=visual-studio) has me run it, Localhost comes up with some stuff relating to the app (its name, a welcome message). The tutorial says to then add "/MvcMovie/" to the URL in the address field. Then, localhost says "No webpage was found for the web address: https://localhost:44379/MvcMovie/".
I'm new at this. Not sure from the tutorial when/if to actually add something to localhost.
Any help will be appreciated.
If you are refering to this:
In the Configure your new project dialog, enter MvcMovie for Project
name. It's important to name the project MvcMovie. Capitalization
needs to match each namespace when code is copied.
The tutorial is saying that your Project's name should be MvcMovie when you create it. Other than that, the tutorial doesn't ask you to go to localhost/mvcMovie. To figure out the routing in an MVC check the next few parts about Controllers-Views-Models. There will be explained about the routing part and how you can access different parts of the URL.
The MvcMovie mentioned in the document does not require you to enter in the URl, it is just the name of the created project:
If you need to use MvcMovie as the routing address in the Url, you can do this:
Controller:
[ApiController]
public class TestController : Controller
{
[HttpGet]
[Route("MvcMovie")]
public IActionResult MvcMovie()
{
return View();
}
}
View demo:
<h1>This is MvcMovie Controller!</h1>
Test url:https://localhost:7040/MvcMovie
Result:
I think you need to know the routing rules in mvc, you can read this document:
Routing to controller actions in ASP.NET Core

Sitecore Wrong Route in MVC

I updated sitecore 7.0 to 7.5 and there are some controller rendering items created by MVC3.
When I execute them in 7.5, it shows an error:
Could not create controller: 'Components'. The current route url is: 'api/sitecore/{controller}/{action}'.
`Message: The controller for path '/api/sitecore/Components/Navigation' was not found or does not implement IController.
The name of controller is Components and action is Navigation
I worked perfectly in Sitecore 7.0.
How can I fix this issue?
Yes, try to append "Controller" into your "components" like "componentsController" and you can also disable CommandRoutePrefix at Sitecore.Speak.Mvc.config file in /App_Config/Includes/
Also, if you want to pass value into specific location, you can use static url instead of #Url.Action(...)

Customize Authorize Redirect

I am using Beta 4 and when I use the [Authorize] attribute, it redirects to /account/login like i'd expect but that's no the name of my URL. I could customize this in web.config but I don't know where to configure it in ASP.NET 5. Any ideas?
Not sure if this will help but I did download VS 2015 RC.
I’ve created a new MVC 6 website project and launched (F5) it. While being unauthenticated, I tried reaching the ManageController which is decorated with the [Authorize] attribute.
Needless to say, I was redirected to the Account/login view but nowhere have I found where this is configured.
I did manage to add the following inside the ConfigureServices() method of the Startup.cs:
services.Configure<CookieAuthenticationOptions>(options =>
{
options.LoginPath = new PathString("/Gazou/Index");
});
Just above the:
services.AddMvc();
I’ve then created my new GazouController with a simple Index IActionResult().
Ran the application again, tried accessing the ManageController but this time, I was redirected to the Index method of my GazouController instead of the default behavior.
Hope this helps.
Vince
I think you didn't format it with code so I can't see it, but this is what I found:
services.Configure<CookieAuthenticationOptions>(opt =>
{
opt.LoginPath = PathString.FromUriComponent("/Auth/Login");
});

MVC Controller named Controllers throws "Server Error in '/' Application."

I'm using ASP.NET MVC 3 (Razor) and have created a Controller named "Controllers" - specifically, the Controller class name is "ControllersController".
Here's a snippet of my "Controllers" Controller:
public class ControllersController : Controller
{
public ActionResult Index()
{
return View();
}
}
In addition to creating the ControllersController class, I created a Razor View (Index.cshtml) that correlates with the ControllersController Index() action. It may be worth noting that I created the Index.cshtml View by right-clicking the Index() method within the Controller and choosing "Add View".
The problem that I am experiencing is, when a browser tries to go to http://localhost/controllers, the following error is thrown:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource
you are looking for (or one of its
dependencies) could have been removed,
had its name changed, or is
temporarily unavailable. Please
review the following URL and make sure
that it is spelled correctly.
Requested URL: /controllers/
There are two points that I'd like to point out:
The error can be avoided if the
browser explicitly goes to
http://localhost/controllers/index
Controllers that are not named
ControllersController don't force
the browser to specify the /index
action in its URL.
With all the naming conventions in MVC, I'm not surprised that a Controller named Controllers causes some strange behavior. My question is; what do I need to do so that I don't have to specify /index in the browser's URL?
This is because you have a folder called "Controllers" on disk in your project. One option would be to rename that folder to something else. This problem won't exist when you publish your site using the Visual Studio publish option because the Controllers folder won't get pushed. A second more cumbersome solution would be to set routes.RouteExistingFiles = true; in the RegisterRoutes function in your global.asax.cs. You then may want to call route.IgnoreRoutes for items in your content folder, etc.
Stay away from using any current names in your code - the world will be a better place, children wont cry, etc.
"With all the naming conventions in MVC, I'm not surprised that a Controller named Controllers causes some strange behavior. "
If it feels weird - don't do it : )
Apparently, the problem has nothing to do with the name of the Controller (i.e. ControllersController), but rather with the name of the URL route.
In my Global.asax.cs, I added a custom route as follows:
public static void RegisterRoutes(RouteCollection routes)
{
//Route /controllers/ to /Home/Index
routes.MapRoute(
"Controllers",
"controllers/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Notice the the custom route (named "Controllers") routes to the HomeController (not ControllersController).
I would expect that when the browser points to http://localhost/controllers, MVC would return the /Home/Index page. Instead, a 404 error is thrown. However, the route succeeds if the browser points to http://localhost/controllers/index. - This is the same symptoms as I mentioned at the beginning of this post.
Based on this test, I think it's safe to assume that the problem is not with the naming convention of the Controller, but rather with the naming convention of the MVC routing.
To move on with building my application, I'm going to change the name of my ControllersController to ControllerSystemsController. In the meantime, I'm interested to know specifically why the MVC router doesn't work as expected for routes that use "controllers" as the name of the controller. Can anyone shed light on this?

Introducing MVC into ASP.Net - 404 error

I have an existing ASP.Net Application, into which I am attempting to introduce MVC2.
Hopefully I can remember the steps, but what I did was the following:
Created a dummy MVC2 project.
Compared and merged .csproj, resulting in the Add Item commands showing MVC2 items.
Compared and merged the web.config
Compared and merged the global.asax.cs
Added Models, Views and Controllers directories
Added HostController with Index action and Index.aspx (no logic)
Amended route to make /Host/Index the default
So now, when I access the application via the root address http://localhost/MyApp it all works.
But, when I access http://localhost/MyApp/Host/Index I get a 404 error. I get the same result for any of the Controller/Actions I created. The only way I can get them to appear is to use the defaults in the routing configuration. I installed Phill Haack's route debugger and it's doing nothing. Obviously there's some problem with my routing, but I can't figure it out.
Any ideas what I've missed?
Bah... turns out that this is to do with IIS 5.1 and MVC routing.
I resolved it by using the following Routes in my application (note the .aspx extensions).
routes.MapRoute("Root", "", new { controller = "Host", action = "Index" });
routes.MapRoute("Default", "{controller}/{action}.aspx", new { controller = "Host", action = "Index" });
Means I can't have clean routes, but at least it works.

Resources