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.
Marked as answer by hnchan on May 08, 2008 04:38 PM
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.
hnchan
Member
18 Points
119 Posts
MVC and Browser Language setting
May 08, 2008 12:08 PM|LINK
Hi All
How could I retrieve the browser language setting through MVC since I couldn't use the request under Controller??
Thanks and Regards
Alex
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: MVC and Browser Language setting
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.
hnchan
Member
18 Points
119 Posts
Re: MVC and Browser Language setting
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?
levib
Star
7702 Points
1099 Posts
Microsoft
Re: MVC and Browser Language setting
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.