protected void Page_PreInit(object sender, EventArgs e)
{
int mobilkullanici = 0;
string useragent = HttpContext.Current.Request["HTTP_USER_AGENT"].ToString();
Regex r = new Regex("(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm)", RegexOptions.IgnoreCase);
Match m = r.Match(useragent);
mobilkullanici = mobilkullanici + m.Groups.Count;
string[] dizi = new string[] { "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-"};
for (int i = 0; i < dizi.Length; i++)
{
if (useragent.Contains(dizi[i].ToString()))
mobilkullanici = mobilkullanici + 1;
}
//Bu değer eğer 1den büyükse Mobil kullancıdır değilse normal PC'dir.
if (mobilkullanici > 1)
this.MasterPageFile = "~/Views/Shared/PortalMobil.Master"; //Burada mobil kullanıcıya istediğiniz işlemi yaptırabilirsiniz. Ben MasterPage'ini değiştirdim mesela
}