开发者

Redirecting Issues

Let's say I have a website www.mysite.com and I want it to be a multilingual site. Following are the things I wanna achieve :-

1. When a user visits my website, I want to fetch the user's country's ISO code. Let's say the ISO is "FR". Now I want the user to be redirected to www.mysite.fr

In case the ISO address can't be fetched, the user will be redirected to www.mysite.com

Now I have used the dll from this site http://ipaddressextensions.codeplex.com/ and used their method which is something like iso3066code(). BUT I am not able to fetch ISO code based on a user's IP address. What is the best method to fetch the ISO code anyway??

2. I have a differenet master page for different countries. Like for France there is France.master, for Germany there is Germany.master, etc. What I want is that firstly the ISO Code of the user should be fetched, then the user should be redirected to the site corresponding to the ISO AND want the corresponding master to load.

Here's a scenario:-

A user from France opens my website by typing "www.mysite.com". Now I want to show the user my site's contents in French so I want him to be redirected to "www.mysite.fr" AND want the France.master to load for all the pages. What I am doing is check the "Top level domain name" entered by user which is "com" in this case, then I fetch the ISO code then if ISO exists, user is redirected to "www.mysite.fr"

IN CASE, ISO cant be fetched , "www.mysite.com" will only be opened for the user.

3. How do I redirect the user?? Response.Redirect("http://www.mysite.fr") is failing and giving errors like :-

"Page is not redirecting properly" I tried changing it to Response.Redirect("http://www.mysite.fr", false) and Response.Redirect("http://www.mysite.fr", true). This didn't work.

4. www.mysite.com and www.mysite.fr aren't two different websites.Just that when is it www.mysite.com, English content will be shown on the website. When it is "www.mysite.fr", French content can be seen inside the website.

What I did was :-

In the Global.asax file :-

I tried fetching ISO code using that dll above from the site ipaddressextensions. Then I created this Application("UserISO") variable in Global.asax file.((Is this a good approach?)) I needed to make it because I wanted to use this global variable within my Global file itself..In some user defined method. Then I am setting master page name in a cookie and using this cookie to change master page dynamically for every content page in the Page_PreInit() event. and lastly I am redirecting the user with " Response.Redirect("http://www.mysite.fr", 开发者_JAVA技巧false)". This response.redirect doesnt work!

Now, AM I on the right path?? I am super confused over how to actually make it work! :( How do multilingual site redirect their users? Where can I learn about all this ? I have tried and tried and tried but this just won't work!

Lastly, there are not really any domain names set for the site as of now. Running it using the IP address set in the IIS. So how do I test my site. How do I really go about it. Am I following the correct approach at all??

Please direct me to the right path. ANY help will be greatly appreciated. Thanks!


Belgium has 3 official languages, you can't find my language by just looking at the ip address or the domain.

The best way to find the language of a visitor is to check the language of his browser. You can find it in Request.Userlanguages.


Don't do this. It's really frustrating when you try to assume what language the user speaks. You're bound to get it wrong for someone eventually. Put some small flag icons or the language name choices on your main page in a highly visible place, and let your visitors chose what site/language they want to browse in.

Facebook's main sign in page is a great example of this.

Edit: The best you could probably do is to use the HTTP1.1 Header Accept-Language as a hint, but even then I think you should push back on this requirement of your project.


You get redirect error because the .fr site is probably the same site as .com, but session cookies are only valid for a certain domain which means that Session_OnStart() is invoked on the redirect as well. One way to circumvent this is to override the redirect/ip-lookup somehow, maybe send in a querystring or a specific landing page that you can identify:

www.site.fr/?overrideredirect=true www.site.fr/redirected.aspx -> which then redirects back to / after Session_OnStart

In order to choose the right master page, you could probably identify which host that was requested and from that override master page in your global.asax, perhaps in the BeginRequest event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜