You must Sign In to post a response.
  • Category: ASP.Net MVC

    Purpose App_Start folder in MVC5

    Hi to all,
    In MVC5, what is the main purpose having 3 default files given below in App_start. There are,
    1.BundleConfig.cs
    2.FilterConfig.cs
    3.RouteConfig.cs


    Regards,
    Karunanidhi.K
  • #767927
    Hi,
    I have been using MVC4 for last 2 years. MVC 5 is just Similar to MVC 4 with few upgrades.
    App_Start is just another folder that groups together ASP.NET MVC configuration, which in previous versions of ASP.NET MVC was done in Global.asax

    As per my understanding i will point out the use of those files.

    1.BundleConfig - Registering all JS and CSS file. So all the file implementation in one place. No need to Import each and every page. Because this is the first file to be called what ever action is performed.

    2. FilterConfig - It will Register the Global Filters. These will be applied to all Actions and Controllers. So instead of adding in all controller or action we can make it in one file.

    3.RouteConfig - This will help to register various route pattern. All projects will have default route config,

    Apart from above we also have some more files like ,

    4.WebApiConfig - This is used to register various WEB API routes like as Asp.Net MVC,as well as set any additional WEB API configurations settings.

    5.AuthConfig - Will register external authentication providers. ( Not have much idea on this).

    So all this file are used for minimizing the files like instead of multiple call just one file call.

    Thanks,
    Mani

  • #767940
    Hai Karunanidhi,
    MVC 5 ccame up with few major changes as compared with the previous version of the ASP.Net MVC. In those major changes, the App_Start folder is one where they have added couple of .cs files like: BundleConfig.cs, FilterConfig.cs, RouteConfig.cs etc.
    1.BundleConfig.cs : This is used for the Bundling and Minification for all the client specific files like JavaScript, JQuery and Css files.
    In this file, we can provide the references to all the client specific files:

    public static void RegisterBundles(BundleCollection bundles)
    {
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/MyFile.js")); // for script file
    bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/MyFile.css","~/Content/site.css"));// for style
    }

    2.FilterConfig.cs : This file is used to add the filters globally so that they can be used throughout the application. Once registering the filter in this files, all the controllers and action can use those filters.
    3.RouteConfig.cs: This file is used to define he routes for the request which needs to be processed. Based on the route, the request will be processed in ASP.Net MVC.
    We can define .the individual route and when the request matches, it validates through the route and process the request.

    public static void RegisterRoutes(RouteCollection routes)
    {
    routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
    routes.MapRoute(name: "MyRoute", url: "{controller}/{action}", defaults: new { controller = "Home", action = "Index"});
    }

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #767944
    BundleConfig is used for Bundling and minification, these are two techniques you can use in ASP.NET 4.5 to improve request load time. Bundling and minification improves load time by reducing the number of requests to the server and reducing the size of requested assets
    With the help of FilterConfig, You can add custom filters to this list that should be executed on each request. If you inherit from the FilterAttribute class or one of its inheritors you can create your own filters, for instance a log filter.
    RoutingConfig is used for routing of path

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments