Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way to verify cookies are enabled for html 5 (mobile) website using asp.net mvc 3
    primarykey
    data
    text
    <p>I know that similar questions have been asked here but I am nevertheless having trouble getting it to work. </p> <p>I am writing an html 5 website using ASP.NET MVC 3 that is targeted to mobile devices. </p> <p>I had previously asked <a href="https://stackoverflow.com/questions/10421121/how-do-you-pass-expensive-data-from-page-to-page-using-asp-net-mvc-3">another question about how to store and retrieve expensive data</a> and decided to go with Session variables.</p> <p>I finished the app and started internal testing and all was well until we realized that the web site is not working on some iPhones. After researching I came to realize that Session variables depend on cookies and that some iPhones ship with cookies disabled by default.</p> <p>Until I come up with a better solution, I want to check to see if cookies are enabled and redirect to an error page. </p> <p>I was hoping that ALL of the code to do this could be written in a base controller but I could not figure out how to do it. So instead I put the following code into the base controller...</p> <pre><code>protected void WriteCookie() { Response.Cookies.Add(new HttpCookie("cookie_test")); } protected bool CookieCheck() { return (Request.Cookies["cookie_test"] != null); } </code></pre> <p>Then in a home controller I am calling the WriteCookie method before loading the view. The view itself has javascript that is redirecting to one of two controllers / actions. The controller / view that will usually be called (because html 5 could not resolve the location) is the ChangeLocation / Index controller/action. In there I have the following code...</p> <pre><code>if (!CookieCheck()) { RedirectToAction("CookieRequired", "Error"); } </code></pre> <p>Even with cookies disabled it is not redirecting to the above error page. </p> <p>So what I am looking for is a best practices approach for solving this problem with a fairly complete code sample.</p> <p>My home controller is pretty much ALWAYS redirecting to another page (in the javascript not the controller). I have a total of about 4 controllers with a total of about 6 actions. </p> <p>My ideal would be to solve this problem completely in the base controller. If not that then I would love for it to work no matter what valid URL is typed (in other words, even if the web app is not entered through Home / Index). If not that then at least I want what I have shown in my code to work (set the cookie in Home / Index and check for it in the other controller / actions) and work even if the redirect is happening in a controller.</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.
    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