I have been working on mvc3 application and trying to localize the same. I came accross this very good site which made me use the logic of identifying the language selection by the user through cookies. What it does is:
-
User clicks the hyperlink of language
-
The clicked setting is saved in a cookie
-
Page is reloaded
-
In the BaseController class the ExecuteCore method is overloaded, here the cookie is read and the CurrentUICulture and CurrentCulture is set.
Now, this works great. But What if the user have disabled the cookie ?
So i feel this wont work.
Then I thot of using a workaround. What i tried was
-
I created a HiddenField
-
User clicks the hyperlink of language
-
The clicked setting is saved in a cookie
-
The clicked setting is also saved in HiddenField
-
Page is reloaded
-
In the BaseController class the ExecuteCore method is overloaded, here if the cookie value is present then its read and the CurrentUICulture and CurrentCulture is set.
-
If cookie is not found then I will try to read the hidden field value from Request object.
But I cant find the hiddenfield in the Request object in the ExecuteCore method.
So am i doing something wrong ?
PLease suggest me with some way. Also I dont want to use the route way of saving the culture.
Hidden fields values are only sent when you submit the form that contains them. If you only click on some hyperlink, the browser redirects to the href that this link is pointing to and no value will be sent, so you cannot expect to read it in your
ExecureCoremethod. So, if you want this to work you will have to include the language as part of the querystring of the link.If you don’t include the value as part of the url (query string or route), and cookies are disabled, the culture value has no way of reaching to your server.