Setting Culture for ASP.NET MVC Application on VS Dev Server and Iis

Setting Culture for ASP.NET MVC application on VS dev server and IIS

Well, I didn't actually find what IIS setting is responsible, but I've overridden it in Application_PreRequestHandlerExecute() and it finally worked:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

Setting up development environment for ASP.NET MVC

ASP.NET Development Server is a mini web server that comes with Visual Studio. The idea is that you wouldn't need to set up IIS for development.

Checkout this question for possible solutions. Mostly I would make sure that localhost is not redirected in your hosts file and also that you are not doing anything funky with a local firewall app that might be blocking certain ports on localhost.

You cannot, as far as I am aware, use Apache. You could configure it to use IIS in your project Properties->Start Options screen by pointing it to a valid IIS directory you have set up.

Edit:
Also try this:

  1. Open a command window (cmd.exe)
  2. Run C:\Program Files\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.Exe /port:8080 /path:c:\mywebpath\ (swap out c:\mywebpath for the path to your app)

You should notice the WebDev server start up in your task bar. You should then be able to browse to http://localhost:8080/default.aspx (or whatever your page is).

If that doesn't work try the same thing but using http://127.0.0.1:8080/default.aspx. If this works but localhost does not then something is redirecting your localhost traffic.

How to configure invariant culture in ASP.NET globalization?

According to the CultureInfo class documentation, an empty string specifies InvariantCulture.

Edit (tested on .NET 3.5 sp1)

By default, Culture and UICulture are set to "" in the web.config. I guess .Net just does its own thing though, and sets them to "en-US" at run time, even though the documentation says that "en" is the invariant culture, not "en-US".

The @Page directive could be interfering with you. If you used the "Generate Local Resources" tool of the page designer, it automatically adds culture="auto" uiculture="auto" to your page directive, which overrides the web.config. If you just delete those and someone uses that tool later, whammo, they come back, set to auto, bugging up your application. If you try to set them to "", you get an error.

Try setting both the web.config and page directive to this and hope for the best?

culture="en-US" uiCulture="en"

Different DateTimeFormat for dev and test environment

If you do want to override these settings for all your pages (instead of giving the User a choice) then the standard way is a setting in web.config :

  <globalization uiCulture="en" culture="en-GB" />

The MSDN page also points you to overriding InitializeCulture() if you want to use code.

InitializeCulture() happens early but I suspect that Application_BeginRequest happens even earlier and that its effects are overridden.

What is the difference between ASP.NET dev server and IIS Express?

Take a look a this post by Scott Guthrie: Introducing IIS Express

We think it combines the ease of use of the ASP.NET Web Server with the full power of IIS. Specifically:

  • It’s lightweight and easy to install (less than 10Mb download and a super quick install)
  • It does not require an administrator account to run/debug applications from Visual Studio
  • It enables a full web-server feature set – including SSL, URL Rewrite, Media Support, and all other IIS 7.x modules
  • It supports and enables the same extensibility model and web.config file settings that IIS 7.x support
  • It can be installed side-by-side with the full IIS web server as well as the ASP.NET Development Server (they do not conflict at all)
  • It works on Windows XP and higher operating systems – giving you a full IIS 7.x developer feature-set on all OS platforms


Related Topics



Leave a reply



Submit