ASP.NET MVC - .NET Framework Part-2 App_Start folder

 App_Start फ़ोल्डर

जब ASP.NET MVC एप्लीकेशन शुरू होती है, तो बैकग्राउंड में कई अलग-अलग काम होते हैं। एप्लीकेशन के किसी भी HTTP रिक्वेस्ट को हैंडल करने और कंट्रोलर तक पहुँचने से पहले एप्लीकेशन कॉन्फ़िगरेशन, रूटिंग मैकेनिज़्म, बंडलिंग, मिनिफ़िकेशन और कई दूसरी चीज़ें सेट अप या कॉन्फ़िगर की जाती हैं। एप्लीकेशन लॉन्च होने के दौरान ज़रूरी सभी कॉन्फ़िगरेशन कोड App_Start फ़ोल्डर में मौजूद अलग-अलग क्लास फ़ाइलों में होते हैं जैसे BundleConfig, FilterConfig, RouteConfig

RouteConfig.cs फ़ाइल App_Start फ़ोल्डर में होती है। ASP.NET MVC एप्लिकेशन में राउटिंग कॉन्फ़िगरेशन के लिए RouteConfig क्लास ज़िम्मेदार होती है। 

using System.Web.Mvc;
using System.Web.Routing;
namespace WebApplication
{
    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 = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

BundleConfig.cs फ़ाइल App_Start फ़ोल्डर में होती है। एप्लिकेशन में bundling कॉन्फ़िगरेशन के लिए BundleConfig क्लास ज़िम्मेदार होती है। 

using System.Web;
using System.Web.Optimization;
namespace WebApplication
{
    public class BundleConfig
    {
        // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));
            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));
            bundles.Add(new Bundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js"));
            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }
    }
}

FilterConfig.cs फ़ाइल App_Start फ़ोल्डर में होती है।

using System.Web;
using System.Web.Mvc;
namespace WebApplication
{
    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }
    }
}


हम पहले ही कॉन्फ़िगरेशन, रूटिंग, बंडलिंग और दूसरी चीज़ों के बारे में बात कर चुके हैं। ये सेटिंग्स App_Start नाम के फ़ोल्डर में होती हैं। App_Start फ़ोल्डर में RouteConfig, BundleConfig, FilterConfig जैसी अलग-अलग क्लास फ़ाइलें होती हैं।


Next: ASP.NET MVC - .NET Framework Part-3 Routing Engine and Routing configuration

टिप्पणियाँ

इस ब्लॉग से लोकप्रिय पोस्ट

Differences between in-process and out-of-process hosting models

Web Fundamental Concepts in Hindi for Beginners - FAQs with their Answers Part-1

Introduction to ASP.NET Core and Web Frameworks