Month: June 2012

301 Redirect – Using Global.asax

Recently came across new query of redirecting website to new domain , and the trouble was we don’t have control over domain management. Real problem was the hosting doesn’t allow web.config based changes or .htaccess , Finally come across global.asax and piece of code that worked out for me. private void Application_BeginRequest(Object source, EventArgs e) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Status = “301 Moved Permanently”; HttpContext.Current.Response.StatusCode = 301; HttpContext.Current.Response.AddHeader(“Location”, “NEW DOMAIN HERE”); } Happy Coding !...

Read More

Check Model State Errors

Recently faced new error in MVC3 Project related to Model State , While checking “ModelState.IsValid”  it was always return false , I wasn’t sure whats going wrong with my ModelState Finally got small piece of code that worked out fine for me ! Here it is ,  var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); Happy Coding !...

Read More