Pages . aspx in View folder in ASP.MVC project

Asked

Viewed 68 times

0

Good afternoon, everyone,

I am a beginner in MVC architecture and I have a question about an ASPNET.MVC. I wonder if it is possible in the "View" folder of the project, to put an "aspx" page along with the "cshtml" files".

If I put the file in the root of the web application, it goes up smoothly but when placing it in the View folder it generates error 404.

I looked for some solutions on the web but did not find much.

Thanks in advance,

Thank you!

  • 1

    My first question is... why?

  • My second question, which version?

  • Hello, the reason would be due to the migration of these aspx pages from a legacy system into webforms to be organized in the same folder where the new system views will be

  • The version would be MVC 5

1 answer

2


In the case of a migration I recommend that you create a folder called "Legacy" or as "Pages" even (if you do not want to make this intention explicit" and add the Ignore of this route in your RouteConfig which is located in the directory App_Start. So MVC will ignore this route in its management.

See Example Below

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");            

        routes.IgnoreRoute("{diretorio}", new { diretorio = "Paginas" });

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
}
  • Blz Leandro, thanks for the tip, to complete the understanding, so aspx pages within the default View folder, even in new implementations can coexist with cshtml pages? Thank you ;)

  • You can even have an aspx inside the default directory Views, provided that it derives from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>. Even, at the very beginning the views were aspx files and not cshtml

  • Excellent! , thank you so much for sharing the knowledge . Big hug!

Browser other questions tagged

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