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
    • Loading...
    • hnchan
    • Joined on 08-10-2007, 1:48 AM
    • Posts 77

    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
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 9:08 AM
    • Posts 516
    • ASPInsiders

    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
    • Loading...
    • hnchan
    • Joined on 08-10-2007, 1:48 AM
    • Posts 77

    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
    • Loading...
    • levib
    • Joined on 07-23-2007, 7:50 PM
    • Redmond, WA
    • Posts 51
    • 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)