Note that there are some explanatory texts on larger screens.

plurals
  1. POReWrite in web.config to go between mobile and desktop sites
    primarykey
    data
    text
    <p>I am finishing up a new mobile website to compliment the desktop version. Currently I have a rewrite rule in the web.config file on my desktop site that looks like so:</p> <pre><code>&lt;system.webServer&gt; &lt;rewrite&gt; &lt;rules&gt; &lt;rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true"&gt; &lt;match url=".*" ignoreCase="true" /&gt; &lt;conditions logicalGrouping="MatchAll"&gt; &lt;add input="{HTTP_COOKIE}" pattern="nomobile" ignoreCase="true" negate="true" /&gt; &lt;add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" /&gt; &lt;/conditions&gt; &lt;action type="Redirect" url="http://m.mysite.com" appendQueryString="false" redirectType="Found" /&gt; &lt;/rule&gt; &lt;/rules&gt; &lt;/rewrite&gt; </code></pre> <p>This works perfect if I never want the user to be able to use the desktop site while on a mobile device, but that is not always the case. Some links on the mobile site DO link back into the desktop version. I have a link on the footer of the mobile site to "view full site" as well. </p> <p>So my question IS: how to properly handle cookie setting on that link and then detecting in the web.config and NOT redirecting to the mobile version IF it exists.... I have a conditional check in the web.config for http_cookie "nomobile", but I don't think it is properly working. Do I just send in a querystring value from the mobile and check that in the global.asax file or does that not work because the web.config runs first?</p> <p>The desktop is a C# MVC4 site on IIS 7.5 if any of that helps, and the mobile site is a simply jquery mobile site.</p> <p>Thank you!</p> <p><strong>EDIT:</strong> I have tried checking the querystring in the global.asax file (code below) but it seems that "Request is not available in this context".</p> <pre><code>// 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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload