Posts

Showing posts from February, 2016

Caching in MVC5 ?

Caching in MVC5 Caching is the most important aspect of high-performance web application.Caching is way of storing data when fetching of data is frequent hence praticlly imprving performnce of application. Advantages of Caching Reducing round trips Reducing Server database round trips Better Performance Lesser Network Traffic For Caching in MVC we use Output Cache Filter. Output Cache Filter This filter will allow us to cache the data for any action method for the specified time, by default the time limit is 60 seconds. This means when any cal is made the data will be cached for next 60 minute after that 60 seconds if there is any call the data will be cached again. Example of using Output Cache Filter [OutputCache(Duration=20, VaryByName="none")] public ActionResult Index() { ViewBag.Message=DateTime.Now.ToString(); return View(); } Here the code will cacche the index page for next 20 seconds. We can check the cache effect by placing the ViewBag.Me

Initializing variable in c#.net ?

We are learning a new language daily so we need to remember how too initialize variables in c#.net so bookmark this and use it as your daily guidebook to initialize variable in c#.net. Initialize variables in C#.net Single Dimensional Array  Integers <code> int[] n1= new int[4]{2,3,1,4}; int[] n2= new int[]{1,2,3,4}; int[] n3= {1,2,3,4,}; </code> Strings <code> string[] s1= new string[4]{"tom","jerry","harry","ben"}; string[] s2= new string[]{"tom","jerry","harry","ben"}; string[] s3= {"tom","jerry","harry","ben"}; </code> Multi-dimensional array. Integer <code> int[,] n1 = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} }; int[,] n2 = new int[,] { {1, 2}, {3, 4}, {5, 6} }; int[,] n3 = { {1, 2}, {3, 4}, {5, 6} }; </code> String <code> string[,] n1 = new string["

Filters in MVC5?

Filters: Filters in mvc are a way to implement cross cutting concerns which means Functionaity that is used aross the application based on different layers. These fnctionality includes logging, exception handling, cacheing, Authorization, Authentication etc. These function are required to kept at single place so as to mkae changes easier.Advavntage that filters provide as they use common logic to implemented using cross cutting concerns that can be applied on different controllers and action methods. There are generally two types of filters that are Global filters and Controller filters.  We can create a Global filter by creating a class nad registering it as a global filter  <code> public class DemoGlobalFilterAttribute : ActionFilterAttribute    {        public override void OnActionExecuting(ActionExecutingContext context)        {            base.OnActionExecuting(context);            context.RequestContext.HttpContext.Response.Write("This is

Attribute based routing in MVC 5 ?

Attribute Based Routing :Attribute based routing can defined as route configuration in the same place where action method is defined. This is way of setting the route configuration for every single action method in same section where action is defined for better usage and fast configuration. To enable Attribute based routing we need to add a small section into the RouteConfig.cs file, public static void RegisterRoutes(RouteCollection routes) { routes.MapMvcAttributeRoutes(); } Optional Parameter: We can specify the optional parameters in the URL in route attribute only using "?" character. [Route("Products/Electronics/{id?}")] public ActionResult GetElectronicItems(int? id) { ViewBag.Id = id; return View(); } Route Constraints :  Specify parameter constraints placing the constraint name after the parameter name separated by colon.Here the action methods needs a id of int type to be worked upon. [Route("Products/Electronics/{id:int}")