Reputation: 18237
I deployed a MVC3 Application that works well in development environment, that's because the date format in the develop machine it's dd/mm/yyyy. But When The application was deploy in the server starts to getting errors in the server side for not valid Dates, because in the server the format of date it's mm/dd/yyyy. Now my question it's Do i need to configure the server?? or only the IIS 7.0 for this specific culture??. Whatever the answer was please let me know how can I do this. I'm working in a windows server 2008 R2 and iis 7.5
Upvotes: 0
Views: 212
Reputation: 101130
The easiest way to make sure that the same culture always is used is to set it in your base controller:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Thread.CurrentThread.CurrentUICulture =
Thread.CurrentThread.CurrentCulture = new CultureInfo(1033); //en-us
}
But a more solid approach is to create a new action filter:
public class UseEnglishCultureAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Thread.CurrentThread.CurrentUICulture =
Thread.CurrentThread.CurrentCulture = new CultureInfo(1033); //en-us
}
}
And tag your controller with it:
[UseEnglishCulture]
public class BaseController : Controller
{
}
Upvotes: 2
Reputation: 8738
What you could do to not make your code culture dependent:
Rightclick your project, and goto properties -> code analysis. Turn on Microsoft Globalisation Rules, and analyse your code.
It will give you warnings for everywhere you used DateTime, and did not specify a culture. For the ones that should be of an independent format, add CultureInfo.InvariantCulture
Upvotes: 0