2012-09-13 2 views
2

ASP.net 웹 사이트가 있습니다. 휴대 기기가 홈 페이지의 페이지로드에 있는지 확인했습니다. 자사의 모바일, 모바일 페이지로 라우팅 장치. 그것은 작동합니다. 그러나 Google에서 내 웹 사이트에 들어 왔을 때 휴대 기기가 모바일 인 경우 모바일 페이지로 라우팅되지 않습니다. 여기에 어떤 문제가 있습니까?ASP.net 모바일 사이트로 리디렉션

제어 문 :

If Request.Browser.IsMobileDevice Then 
     Response.Redirect("MobileHomePage.aspx", True) 
    End If 

답변

4

IsMobileDevice 100 % 신뢰할 수 없습니다.

어느 쪽이 방법 만이 사용하여 더 많은 행운이 있어야합니다 (신뢰할 수있는 가능성이 99 %?) :

Public Shared Function IsMobile() As Boolean 
    Dim curcontext As HttpContext = HttpContext.Current 
    Dim user_agent As String = curcontext.Request.ServerVariables("HTTP_USER_AGENT") 
    user_agent = user_agent.ToLower 

    ' Checks the user-agent 
    If (Not (user_agent) Is Nothing) Then 
     ' Checks if its a Windows browser but not a Windows Mobile browser 
     If (user_agent.Contains("windows") AndAlso Not user_agent.Contains("windows ce")) Then 
      Return False 
     End If 
     ' Checks if it is a mobile browser 
     Dim pattern As String = "up.browser|up.link|windows ce|iphone|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp" 
     Dim mc As MatchCollection = Regex.Matches(user_agent, pattern, RegexOptions.IgnoreCase) 
     If (mc.Count > 0) Then 
      Return True 
     End If 
     ' Checks if the 4 first chars of the user-agent match any of the most popular user-agents 
     Dim popUA As String = "|acs-|alav|alca|amoi|audi|aste|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|opwv|palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|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|w3c |" & _ 
     "wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda|xda-|" 
     If popUA.Contains(("|" + (user_agent.Substring(0, 4) + "|"))) Then 
      Return True 
     End If 
    End If 

    ' Checks the accept header for wap.wml or wap.xhtml support 
    Dim accept As String = curcontext.Request.ServerVariables("HTTP_ACCEPT") 
    If (Not (accept) Is Nothing) Then 
     If (accept.Contains("text/vnd.wap.wml") OrElse accept.Contains("application/vnd.wap.xhtml+xml")) Then 
      Return True 
     End If 
    End If 

    ' Checks if it has any mobile HTTP headers 
    Dim x_wap_profile As String = curcontext.Request.ServerVariables("HTTP_X_WAP_PROFILE") 
    Dim profile As String = curcontext.Request.ServerVariables("HTTP_PROFILE") 
    Dim opera As String = curcontext.Request.Headers("HTTP_X_OPERAMINI_PHONE_UA") 
    If ((Not (x_wap_profile) Is Nothing) OrElse ((Not (profile) Is Nothing) OrElse (Not (opera) Is Nothing))) Then 
     Return True 
    End If 
    Return False 
End Function 
+0

이 기능 주셔서 감사합니다! 시간이 있다면, 어떻게 작동하는지 조금 설명해 주시겠습니까? – Greesemonkey3

관련 문제