Removing part of the link on ASP.NET MVC routes

Asked

Viewed 130 times

1

My Routeconfig is configured this way:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    name: "Default",
    url: "{empresa}/{controller}/{action}/{id}",
    defaults: new { empresa = "", controller = "Login", action = "Index", id = UrlParameter.Optional }
);

My access to controllers and actions is occurring normally, however I have calls to *.aspx files for my reports, these files are in a folder called "Reports", when I will perform the call to they are returning me this way to url: "http://localhost/mycompany/Reports/Customedio.aspx"

This way it does not find the respective file.

I need to access the url this way: "http://localhost/Reports/Customedio.aspx"

I found some examples like:

routes.Ignore("{*allaspx}", new {allaspx=@".*\.aspx(/.*)?"});

routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});

routes.IgnoreRoute("{Content}/{*pathInfo}");

routes.IgnoreRoute("myroute");
routes.IgnoreRoute("myroute/{*pathInfo}");

But I did not succeed with any of these examples.

2 answers

0

It can create another route or modify the one you are and leave as below :

     routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new {controller = "Login", action = "Index", id = UrlParameter.Optional }

);

0


Above the route Default, use like this:

routes.MapRoute(
    name: "Relatorios",
    url: "{empresa}/Relatorios/{action}",
    defaults: new { empresa = "", controller = "Relatorios", action = "Index" }
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.