要了解某個(gè)網(wǎng)站是在移動(dòng)設(shè)備上打開(kāi)的還是在pc web瀏覽器中打開(kāi)的,我們可以有以下綜合的幾種方式來(lái)搞定:
通過(guò)判斷Request.UserAgent中的具體信息來(lái)分析判斷,因?yàn)閁serAgent包含了很多的信息,所以我們可以根據(jù)其中的某些信息來(lái)進(jìn)行判斷,具體的判斷方式如下:
(1)string strUserAgent = Request.UserAgent.ToString().ToLower(); |
if (strUserAgent != null ){ |
if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains( "iphone" ) || |
strUserAgent.Contains( "blackberry" ) || strUserAgent.Contains( "mobile" ) || |
strUserAgent.Contains( "windows ce" ) || strUserAgent.Contains( "opera mini" ) || |
strUserAgent.Contains( "palm" )){ |
Response.Redirect( "DefaultMobile.aspx" ); |
(2)((System.Web.Configuration.HttpCapabilitiesBase)Request.Browser).IsMobileDevice |
(3)public static boolean choose(String userAgent){ |
Agent.indexOf( "WapI" ) > -1 || |
userAgent.indexOf( "MC21" ) > -1 || |
userAgent.indexOf( "AUR" ) > -1 || |
userAgent.indexOf( "R380" ) > -1 || |
userAgent.indexOf( "UP.B" ) > -1 || |
userAgent.indexOf( "WinW" ) > -1 || |
userAgent.indexOf( "UPG1" ) > -1 || |
userAgent.indexOf( "upsi" ) > -1 || |
userAgent.indexOf( "QWAP" ) > -1 || |
userAgent.indexOf( "Jigs" ) > -1 || |
userAgent.indexOf( "Java" ) > -1 || |
userAgent.indexOf( "Alca" ) > -1 || |
userAgent.indexOf( "MITS" ) > -1 || |
userAgent.indexOf( "MOT-" ) > -1 || |
userAgent.indexOf( "My S" ) > -1 || |
userAgent.indexOf( "WAPJ" ) > -1 || |
userAgent.indexOf( "fetc" ) > -1 || |
userAgent.indexOf( "ALAV" ) > -1 || |
userAgent.indexOf( "Wapa" ) > -1 || |
userAgent.indexOf( "Oper" ) > -1){ |
(4) if (HttpContext.Current.Request.Headers[ "user-agent" ] != null && HttpContext.Current.Request.Headers[ "user-agent" ].ToLower().ToString().IndexOf( "mozilla" ) != -1){ |
HttpContext.Current.Response.Redirect( "http://www. " ); //PC |
HttpContext.Current.Response.Redirect( "http://wap " ); //Mobile ClientTypeTesting. |
當(dāng)然我們還可以根據(jù)設(shè)備的分辨率和屏幕大小來(lái)判斷是移動(dòng)設(shè)備還是pc設(shè)備,但是這個(gè)準(zhǔn)確性比較低。
優(yōu)酷的站點(diǎn)是通過(guò)網(wǎng)絡(luò)的Ip地址來(lái)進(jìn)行判斷的,如果是移動(dòng)網(wǎng)絡(luò),瀏覽器訪(fǎng)問(wèn)站點(diǎn)時(shí)就會(huì)跳轉(zhuǎn)到3GP網(wǎng)站,否則就跳轉(zhuǎn)到PC站點(diǎn)。