4
I’m trying to change a route in my project, the control is like this:
public class TagController : Controller
{
// GET: Tag
private MYEntities db = new MYEntities ();
[Route("tags")]
[OutputCache(Duration = 36000, VaryByParam = "none")]
public ActionResult Index()
{
var t = db.TAGs.OrderBy(p => p.DESCRIPTION);
return View(t.ToList());
}
}
When I run the URL:
http://localhost:7071/tags
It returns the error:
Server Error in Application '/'.
Unable to find resource.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could not be removed, its name was changed or is temporarily unavailable. Scan the URL and make sure which is correctly typed.
Requested URL: /tags
Version Information: Microsoft . NET Framework Version:4.0.30319; Version of ASP.NET:4.0.30319.34248
Altering:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Categoria", action = "Index", id = UrlParameter.Optional }
);
}
}
There is a view Index.cshtml
inside the briefcase Tag
inside the briefcase Views
, I believe that it is not a problem that the view does not exist and the route is not working.
Another thing is that if you rotate with:
http://localhost:7071/Tag/Index
Also from the mistake that there is no /Tag/Index
Taking note [Route("tags")]
of the method Index
it works with the above URL.
I added the following code to Routeconfig, but it didn’t work:
routes.MapRoute(
name: "teste",
url: "tags",
defaults: new { controller = "Tag", action = "Index", id = UrlParameter.Optional }
);
I’d like to use the Route[("tags")]
how monstrous this link
Just by looking, maybe I’ve seen the error... You declared this route you’re trying to access ? In Routesconfig same... And if you try to access the url:
http://localhost:7071/Index
, works ?– Érik Thiago
I put more information about the problem, the
RouteConfig
has not been changed, is an application of thing controls, I have not changed virtually anything of configuration.– Ricardo
So maybe that’s the problem... Asp.net mvc recognizes only the routes that are declared and configured in Routes... Try adding a new route in the Routes file, a copy and paste even, below the default route, if it works we put as a response.
– Érik Thiago
I added another route, it didn’t work, I put more information in the question
– Ricardo
And so [Route("/Tags/Index")] ?
– Érik Thiago
It wasn’t, the impression is that the Route does not work.
– Ricardo
Just try to comment on this default route and leave yours to watch...
– Érik Thiago