tags:

views:

67

answers:

2

ok here's the thing... You fetch user's IP address and based on his/her country you redirect the user to a specific webpage..Now how do you change the master page dynamically ? this is how I am redirecting the user :-

http://stackoverflow.com/questions/3690278/fetching-ip-address-and-displaying-country-in-c-and-asp-net

its not like user clicks some button or something and u then change the master page..i want it changed when user is redirected so what I wanna know is what how exactly do I go about it..

public partial class testClass: System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

       if(redirected to site1)
          {
                Use this master page1
          }   
       else
           if(redirected to site2)
            {
                Use this master page2
            } 
       }
}

So how do I like check that what SITE user has been redirected to ?? Also HOW to apply the specific master page now that the user has been redirected ??

I just need an idea how to go about it..thnx

[EDIT] plz check the code block below...how do i fetch the URL that the user has been redirected to ?? I actually need just the "iso3166TwoLetterCode" variable's value(see the link to my earlier ques plz) and based on that will be changing the master page...I cant figure out how to fetch that value or even use that class (that's got this variable) in my testClass

protected void Page_PreInit(object sender, EventArgs e)
    {
        if(user Has been redirected to www.site.in )
        {

        this.MasterPageFile = "master1.master";
        }

        if(user Has been redirected to www.site.fr )
        {

        this.MasterPageFile = "master2.master";
        }


    }
A: 

It sounds like you're not redirecting to another site, just sending them to a page with a querystring like "language=en". If so, then you need to get it with Request.QueryString and append it to a base master page name.

Steven Sudit
okk..so if it IS a webpage..how do I like fetch the URL (eg-www.mysite.in) and then check it using "Request.QueryString" ..after that how do I change the master page ?
Serenity
Based on your example, you're not using a querystring at all. Rather, you have multiple subdomains set up, probably on a virtual server. In that case, try `Request.Uri`. If that doesnt't work, `Request.ServerVariables["Host"]` will.
Steven Sudit
Allow me to correct myself: The HTTP header is called "Host", but you have to refer to it here through "HTTP_HOST". Alternately, I think "URL" will do what you want.
Steven Sudit
A: 

To find out the country two letter code, do what this sample code from http://ipaddressextensions.codeplex.com/ does:

using System.Net;
using WorldDomination.Net;

string userHostIpAddress = "203.1.2.3";
IPAddress ipAddress;
if (IPAddress.TryParse(userHostIpAddress, out ipAddress))
{
    string country = ipAddress.Country(); // return value: UNITED STATES
    string iso3166TwoLetterCode = ipAddress.Iso3166TwoLetterCode(); // return value: US
}

you can then try something like this to change the master:

protected void Page_PreInit(object sender, EventArgs e)
{
    this.MasterPageFile = "NewMasterSite.master";
}
Philipp
could you please check the additional details I just added?? thnx
Serenity
I thought you had already implemented this.
Philipp
figured out how to fetch that code off the url..got help here http://stackoverflow.com/questions/3698196/how-do-i-check-for-a-urls-top-level-domain-in-asp-net-c
Serenity