Mobile 在web.config中重写以在移动和桌面站点之间切换
我正在完成一个新的移动网站,以补充桌面版。目前,我的桌面网站上的web.config文件中有一条重写规则,如下所示:Mobile 在web.config中重写以在移动和桌面站点之间切换,mobile,web-config,rewrite,iis-7.5,httpcookie,Mobile,Web Config,Rewrite,Iis 7.5,Httpcookie,我正在完成一个新的移动网站,以补充桌面版。目前,我的桌面网站上的web.config文件中有一条重写规则,如下所示: <system.webServer> <rewrite> <rules> <rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true"> <match url=".*" ignoreCase="true" /&g
<system.webServer>
<rewrite>
<rules>
<rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_COOKIE}" pattern="nomobile" ignoreCase="true" negate="true" />
<add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" />
</conditions>
<action type="Redirect" url="http://m.mysite.com" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
正是时候。今天一早我就在寻找这个确切的答案。希望有人能插话帮忙。如果我在搜索时找到了答案,我也会在这里告诉你。
// create and set cookie if ?nomobile detected
string forcedesktop = HttpContext.Current.Request["nomobile"];
if(forcedesktop != null){
HttpCookie nomobile = new HttpCookie("nomobile");
Request.Cookies.Add(nomobile);
}
}