MVC and Browser Language setting

Last post 05-08-2008 11:34 PM by levib. 3 replies.

Sort Posts:

  • MVC and Browser Language setting

    05-08-2008, 8:08 AM
    • Member
      18 point Member
    • hnchan
    • Member since 08-10-2007, 1:48 AM
    • Posts 119

    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

     

  • Re: MVC and Browser Language setting

    05-08-2008, 10:58 AM
    Answer
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 2:08 PM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

    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.

  • Re: MVC and Browser Language setting

    05-08-2008, 12:40 PM
    • Member
      18 point Member
    • hnchan
    • Member since 08-10-2007, 1:48 AM
    • Posts 119

    Thanks, it works now.

    The problem happened is because I try HttpContext.Current.Request.UserLanguages but not work.. BTW, Why HttpContext.Current not work?

  • Re: MVC and Browser Language setting

    05-08-2008, 11:34 PM
    • Contributor
      4,545 point Contributor
    • levib
    • Member since 07-23-2007, 7:50 PM
    • Redmond, WA
    • Posts 785
    • AspNetTeam

    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.

Page 1 of 1 (4 items)