BundleConfig.cs -
This is used to create and register bundles for CS and JS files.By default various bundles are added in this file including jQuery,jQueryUI,jQuery validation,Modernizer and Site Css..
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
//Adding StyleBundle to BundleCollection
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.min.css",
"~/Content/mystyle.min.css"));
//Adding ScriptBundle to BundleCollection
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery-1.7.1.min.js",
"~/Scripts/jquery.validate.min.js"));
}
}
AuthConfig.cs -
Used to register external authentication providers for eg. if you want to enable users to log in with
credentials from an external provider, such as Facebook, Twitter, Microsoft, or Google, and then integrate some of the functionality from those providers into your web application.
RouteConfig.cs -
This is used to register various route patterns for your Asp.Net MVC application. By default,one route is registered here named as Default Route.
WebApiConfig.cs -
This is used to register various WEB API routes like as Asp.Net MVC,as well as set any additional WEB API configurations settings.
FilterConfig.cs -
This is used to create and register global MVC filter error filter,action filter etc.By default it contains
HandleErrorAttribute filter.
This is used to create and register global MVC filter:
for eg:-
1. Authentication filters (Executed First)
2. Authorization filters
3. Action filters
4. Result filters
5. Exception filters (Exected Last)
Configuring Filters -
You can configure your own custom filter into your application at following three levels:
1. Global level
By registering your filter into Application_Start event of Global.asax.cs file:
protected void Application_Start()
{
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
}
2. Controller level
By putting your filter on the top of the controller name:
[Authorize(Roles="Admin")]
public class AdminController : Controller
{
// Logic goes here
}
3. Action level
By putting your filter on the top of the action name:
public class UserController : Controller
{
[Authorize(Users="User1,User2")]
public ActionResult LinkLogin(string provider)
{
// Logic goes here
return View();
}
}
No comments:
Post a Comment