ASP.NET ile Mobil Kullanıcıları Mobil Sayfaya Yönlendirmek
27 Şubat 2010
1 Yorum
ASP.NET 4.0 ile aşağıdaki kod yardımıyla mobil kullanıcıları algılayabilir ve uygulamanın mobil sayfasına yönlendirebilirsiniz;
private static readonly Regex MobileRegex = new Regex(@"(nokia|sonyericsson|blackberry|IPHONE|samsung|sec-|windows ce|motorola|mot-|up.b|midp-)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public bool IsMobile
{
get
{
HttpRequest r = HttpContext.Current.Request;
if (r.Browser.IsMobileDevice)
return true;
if (!string.IsNullOrEmpty(r.UserAgent) && MobileRegex.IsMatch(r.UserAgent))
return true;
return false;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsMobile)
Response.RedirectPermanent("Mobile.aspx", true);
}
Categories: ASP.NET, Programlama ASP.NET, aspnet, browser, httpcontext, ismatch, ismobile, ismobiledevice, mobile, readonly, redirectpermanent, regez, request, response, static