Click here to Skip to main content
15,666,926 members
Articles / Web Development / ASP.NET
Posted 4 Aug 2011

Tagged as


12 bookmarked

Cookieless Sessing Using MVC + Post Enabled Forms

Rate me:
Please Sign up or sign in to vote.
4.57/5 (5 votes)
6 Sep 2011CPOL2 min read
Cookieless sessing using MVC and post enabled forms.


The code provided allows the programmer to use standard functions in order to maintain POST in forms when using a cookieless session and MVC.

Using the code  

Once the classes are added to your project, it's as simple to use the new functions as before. 

using (Html.BeginFormNoCookies("Claim")) { %>    
     //Form Contents here
<%} %>

Form ID is the only parameter. It is technically not required, except for when Client Validation is enabled.

How it works

The existing BeginForm is just an extension and that is exactly how I implemented this. In fact, I downloaded the source for Microsoft's MVC2 FormExtension. I changed the function names to not cause any confusion. A new parameter had to be added in order to deal with the fact that I wasn't able to maintain the dynamic form ID creation since some existing methods were internal to System.Web.MVC. The next major part was constructing the URL and always including the session ID as well as any actions, IDs, or query parameters.

I created a class called CookielessHelper. This is what creates the URL. The URL is constructed around the Controller. It is always expected to be in the following format: /{Root Information}/{Controller}/{Anything}?{Query}. The session ID is always added before the controller and everything else is always preserved.


This version as of now does not have Route modifications enabled. If you use any other function than the one listed, the session ID will not be added. All other functions are currently commented out until they can be completely implemented. I am sure it is not difficult, but I don't need it at this point.


  • 8/4/11 - Linus Concepcion pointed out that I can get the Controller by way of the HTMLHelper. Thanks! (Removed require parameter View Page.)
  • 8/4/11 - Initial release.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer
United States United States
Graduate of University of Louisiana at Lafayette in computer science.

Comments and Discussions

GeneralMy vote of 5 Pin
chriszwang29-Sep-11 11:31
chriszwang29-Sep-11 11:31 
GeneralRe: My vote of 5 Pin
Corey Fournier11-Apr-12 2:15
Corey Fournier11-Apr-12 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.