Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 09, 2008 03:34 AM by levib
May 08, 2008 12:08 PM|LINK
How could I retrieve the browser language setting through MVC since I couldn't use the request under Controller??
Thanks and Regards
May 08, 2008 02:58 PM|LINK
Who said you can't use the request under Controller?
You can. There's even a property called Request on the Controller (i wonder what that's there for). It's not available in the constructor but there are several places you can put common code that runs before every action. like OnActionExecuting for example.
it's just this.Request.UserLanguages to get an array of accepted languages.
If i've misunderstood you please describe your problem in more detail.
May 08, 2008 04:40 PM|LINK
Thanks, it works now.
The problem happened is because I try HttpContext.Current.Request.UserLanguages but not work.. BTW, Why HttpContext.Current not work?
May 09, 2008 03:34 AM|LINK
HttpContext is not easily testable, hence it and other common types have been abstracted away. For example, the System.Web.Abstractions assembly contains a type HttpContextBase which mimics HttpContext. Similarly, there is a RequestContextBase that mimics
RequestContext. The Controller.Request property is actually a RequestContextBase and should be used in place of HttpContext.Current.Request.