Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Cookieless Sessing Using MVC + Post Enabled Forms

0.00/5 (No votes)
6 Sep 2011 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here