コメント
コメントの投稿
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。
reg add HKLM\SOFTWARE\Microsoft\InetStp /v MajorVersion /t REG_DWORD /d 0x09 /f /reg:64
%userprofile%\download\rewrite_x64_ja-JP.msi
reg add HKLM\SOFTWARE\Microsoft\InetStp /v MajorVersion /t REG_DWORD /d 0x0a /f /reg:64
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="MobileRedirect" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_USER_AGENT}" pattern="(^DoCoMo|^KDDI|^Up.Browser|^SoftBank|iPhone|iPod|Android|Windows Phone|^vodafone|^J-PHONE|Googlebot-Mobile|-Mobile|_Mobile)" />
</conditions>
<action type="Redirect" url="/mobile/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Namespace Master
Public Class PCSiteMasterPage
Inherits System.Web.UI.MasterPage
Private Sub PCSiteMasterPage_Init(sender As Object, e As EventArgs) Handles Me.Init
If Me.IsMobileDevice() = True Then
'リダイレクトするURLを組み立てます。
Dim scheme As String = HttpUtility.HtmlEncode(Request.Url.Scheme)
Dim host As String = HttpUtility.HtmlEncode(Request.Url.Host)
Dim page As String = HttpUtility.HtmlEncode(Request.RawUrl)
Dim port As Integer = Request.Url.Port
If port = 80 OrElse port = 443 Then
port = 0
End If
Dim url As String = scheme + "://" + host + IIf(port > 0, ":" + port.ToString(), "") + "/mobile" + page
'302リダイレクトで画面遷移させます。
Response.Redirect(url, True)
End If
End Sub
Protected Sub PageMasterPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
''' <summary>
''' モバイル端末のアクセスかどうかを判定する
''' </summary>
''' <returns>True:スマホ/False:PC</returns>
Private Function IsMobileDevice() As Boolean
Dim userAgent As String = HttpUtility.HtmlEncode(Request.UserAgent).ToLower()
'Androidのタブレットに関しては一貫性が無い為、考慮していません。
Dim allowedAgents As String() = New String() {"windows nt", "ipad"}
'Goolebot-Mobileはmobileでヒットする
Dim deniedAgents As String() = New String() {"iphone", "ipod", "android", "windows phone",
"mobile",
"docomo", "softbank", "kddi", "vodafone", "j-phone",
"up.browser"}
For Each aa As String In allowedAgents
If userAgent.Contains(aa) = True Then
'PCと判定
Return False
End If
Next
For Each da As String In deniedAgents
If userAgent.Contains(da) = True Then
'スマホと判定
Return True
End If
Next
'その他はPCと判定
Return False
End Function
End Class
End Namespace
<script type="text/javascript">
window.onload = function () {
MobileRedirect();
}
function MobileRedirect() {
var agent = navigator.userAgent;
if (agent.indexOf('Windows NT') < 0 &&
agent.indexOf('iPad') < 0 &&
(agent.indexOf('iPhone') >= 0 ||
agent.indexOf('iPod') >= 0 ||
agent.indexOf('Windows Phone') >= 0 ||
agent.indexOf('Android') >= 0 ||
agent.indexOf('Mobile') >= 0)) {
//if (window.confirm('スマートフォン向けサイトに移動しますか?')) {
location.href = "/mobile/index.aspx";
//}
}
}
</script>
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。