the resource cannot be found asp.net mvc - asp.net

hi i already tried some solution available on stack overflow...some of them are configuring in routeconfig, going to project properties and creating a virtual directory. But none of them work for me. I've been working on this project and i don't know what happened suddenly. I've tried restarting laptop as well as visual studio . Please help it was working fine before
UPDATE:i have 2 controllers that are not working properly admin and account controller both have views as well as their corresponding controller

Remove all your existing routes and just use the default route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
This should keep things simple and should also work with your existing controller/actions.

I think the issue is to do with your routes. Can you try an explicit route like the one below and check that it works?
routes.MapRoute(
name: "AdminIndex",
url: "admin/index",
defaults: new { controller = "Admin", action = "Index" }
);

Can you try adjusting your admin route like so:
routes.MapRoute(
"Admin",
"{controller}/{action}/{id}",
new { action = "Index", controller = "Admin", id = UrlParameter.Optional }
);

Related

How to redirect the main URL to new path in ASP.NET MVC

I am using ASP.NET MVC, In localhost, using the web, I changed the start URL option it works fine there, once I published it to the main domain, it is not working on that. I hope anyone can help me. I want to redirect from
domain.com/
to
domain.com/Home/Index
Thanks a lot!
you need to change your default route as this
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
on startup the default route is initialized and hence redirected to the above website as
domain.com/Home/Index

ASP.NET Core MVC route to controller any child url like "admin/*"

I want to route any url address like /admin/* as my admin is on Angular2 and uses its routing. I tried template: "admin/{*url}"though it works not only with /admin url but with any other. Is there any way to solve this problem?
Add this code in your WebApiConfig.cs file :
config.Routes.MapHttpRoute(
name: "some name",
routeTemplate: "admin/{*url}",
defaults: new { controller = "Admin", action = "Your default action here" });
Set the default controller in defaults.

Navigate from an area to a page with no area in ASP.NET

I set up my routing to load /AreaName/Home/Indexby default and when adding this
<a asp-area="" asp-controller="Application" asp-action="Index"</a>,
to Index.cshtml I would expect it to go to /Application/Index, but when hovering over the link the url looks like this localhost:######/AreaName/Application/ instead of localhost:######/Application/.
I think my routing is a bit off. Here's what I tried:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "Default",
template: "{area}/{controller}/{action}/{id?}",
defaults: new { area = "AreaName", controller = "Home", action = "Index" }
);
routes.MapRoute(
name: "SomeName",
template: "{area}/{controller}/{action}/{id?}",
defaults: new { area = string.Empty, controller = "Application", action = "Index" }
);
}
What am I doing wrong?
Your routing table should have a default route without an area, your current configuration will always lead to a route with area name = AreaName because you defaulted it to "AreaName" in your first route.
Copy the first route and remove the area section from it and remove the second one.

MVC4 Why can't route as .html file?

I'm use visual studio 2012 with MVC4.
I want some web page looks like .html suffix. So I add this code on RouteConfig:
routes.MapRoute(
name: "Static",
url: "{controller}/{action}/{id}.html",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
But the problem is I can't access it, the page always returns 404, and shows message:
the resource is not found or removed.......
Is there any way can let it route as html page? thanks
Disable the handler for the .html extension.

ASP.Net MVC No routes but default are working

I have added a new Controller to my application, and then from there added in a new View (right click, add view on the context menu)
I have added the route to the Route table, but when I browse to it I get a 404.
I can only assue that this is something fundamental that is wrong, as if I replace the values in the default route, I still cannot access my page.
The route table is;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Classroom",
"{controller}/{action}/",
new { controller = "Classroom", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
//defaults: new { controller = "Classroom", action = "Index", id = UrlParameter.Optional }
);
there is only a return View(); in the index method. I have installed Glimpse, but as I am getting a 404, I cannot actually see the url that is being passed back.
So, what techniques / tricks are there I can use to track this down, (and any common gotcha's that could be causing this?)
Visual Studio 2012, using the inbuilt webserver.
This is Fixed. It was a stupid Gotcha on my part. The Controller was Called Classroom not ClassroomController
I have added the route to the Route table
No, you don't need to add any route for that. Get rid of the Classroom route from your Global.asax and leave only the Default one. Now you could safely navigate to your controller using /classroom/index which will render the Index action of the ClassroomController.

Resources