Click here to Skip to main content
Click here to Skip to main content

Cookieless Sessing Using MVC + Post Enabled Forms

, 6 Sep 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Cookieless sessing using MVC and post enabled forms.

Introduction 

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.

Note

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.

History

  • 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.

License

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

Share

About the Author

Corey Fournier
Software Developer
United States United States
Graduate of University of Louisiana at Lafayette in computer science.

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberchriszwang29-Sep-11 11:31 
GeneralRe: My vote of 5 PinmemberCorey Fournier11-Apr-12 2:15 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 6 Sep 2011
Article Copyright 2011 by Corey Fournier
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid