Note that there are some explanatory texts on larger screens.

plurals
  1. POCookie Value is always Null
    primarykey
    data
    text
    <p>I have a mobile site with a link to view the main site.</p> <p>By default, when a mobile user goes to my main site it detects the mobile device and redirects to the mobile site.</p> <p>Once on the mobile site, if the user then clicks, "View main site" it creates a cookie and redirects back to the main site. The main site detects the cookie and as a result doesn’t redirect them back; it always accepts the main site as their preferred choice.</p> <p>The problem is, on the main site, it can detect the cookie, but the value is always null and the expiry is always DateTime.MinValue.</p> <p><strong>Mobile URL = mobile.mysite.co.uk</strong></p> <p><strong>Main Site = mysite.co.uk</strong></p> <p>Here is my code...</p> <p><strong>Link To Main Site From Mobile Site</strong></p> <pre><code> public ActionResult ViewMainSite() { string CookieValue = "Always Show the Main Site"; HttpCookie Cookie = new HttpCookie("ShowMainSite"); // Set the cookie value and expiry. Cookie.Value = CookieValue; Cookie.Expires = DateTime.Now.AddYears(1); // Add the cookie. Response.Cookies.Add(Cookie); return Redirect("mainSiteURL"); } </code></pre> <p><strong>Main Site Action Filter - Detect Mobile User</strong></p> <pre><code> /// &lt;summary&gt; /// Redirect If Mobile Action filter class /// &lt;/summary&gt; public class RedirectIfMobile : ActionFilterAttribute { /// &lt;summary&gt; /// override the OnactionExecuting Method /// &lt;/summary&gt; /// &lt;param name="filterContext"&gt;&lt;/param&gt; public override void OnActionExecuting(ActionExecutingContext filterContext) { // check to see if the have the main site cookie var Cookie = filterContext.HttpContext.Response.Cookies.Get("ShowMainSite"); if (Cookie != null) { if (Cookie.Value == null || Cookie.Expires &lt; DateTime.Now) { filterContext.HttpContext.Response.Redirect("MobileURL"); } } base.OnActionExecuting(filterContext); } } </code></pre> <p>can any one see why this is happening ?</p> <p>any help is most appriciated.</p>
    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.
 

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