• CurrentCulture can not be set to Neutural Culture

    var c = CultureInfo.GetCultureInfo("en");
    Console.WriteLine(c.Name); //en
    var c2 = CultureInfo.CreateSpecificCulture("en");
    Console.WriteLine(c2); //en-US
    Thread.CurrentThread.CurrentCulture = c2; //ok
    //following with throw
    //System.NotSupportedException: Culture 'en' is a neutral culture.
    Thread.CurrentThread.CurrentCulture = c; 
    
  • How Routing Works in asp.net mvc

    The mvc stack start with the UrlRoutingModule. The module handle two HttpApplication event.

  • HttpContextBase.Items

    When you using controller, you can easily access HttpContext property, which is not an System.Web.HttpContext, but a HttpContextBase object. This object has a handy Items dictionary, which can allowed you share data over a the whole request.

  • TempData of Controller

    TempData is property of Controller. The TempData is used to save the state from page redirected from to the page redirected. So let say, your request is handled by controller1.method1, for some reason, it should be redirected to controller2.method2. Before the redirection take place, you can save some data in the TempData, then http status code 302 and new url are returned to browser, and browser make a new request using new url. In the new action method, the TempData can be restored. This behavior is showed in the following code in the Controller

    //Controller member
    protected override void ExecuteCore() {
        TempData.Load(ControllerContext, TempDataProvider);
    
    
  • Extension point in asp.net mvc

    1. Extending route.

      Route matching is first step mvc framework, we can customize how route is matched by adding constraint, and default, and dataToken. We can implement IRouteConstraint. Here is ASP.NET MVC Tip #30 – Create Custom Route Constraints

    2. Extending IRouteHandler

      When we register route, by default the route handler is MvcRouteHandler. We can create a class implmenting IRouteHandler, of we can sub class MvcRouteHandler

    3. Exending MvcHandler

      MvcHandler is IHttpHandler, we can substitute with a MvcHandler sub class, or a complete new IHttpHandler , or override MvcHandler's ProcessRequest method. We can override ProcessRequest(HttpContextBase httpContext) method.