ASP.NET MVC: Best Practices for Storing Session State in a Manual-Like Application

Let's say I have a web application implemented as a set of wizard pages for editing a complex object. Until the user clicks the Finish button, the object will not be saved in the internal system (requirement), so at the same time I have to store all the information about the object in some session state.

In addition, some wizard pages should display combo boxes and lists with a potentially large number of items. These items are retrieved from the internal system using a web service.

By the way, the wizard allows the user to freely switch from one page of the wizard to any other (using the links on the tab on top of the form), so this is not a simple thing "next, next ... end".

Additional limitation: the web application runs in the web farm, and the client is tired of using the session state on the server side. At best, they want the session size to be minimal (they had problems with this in the past).

So basically there are two problems:

  • How / where to store data entered by the user in the wizard?
  • Should the combo / list items received from the internal block be cached, and if so, where?

The options I'm considering are:

  • WebForms ViewState ( HTML-). . , HTML- , - .

  • , , , , - ( ).

. ?

+5
8

? , div div, . , , .

+5

? , . .

+3

, . . , .

//Here a class we're going to use
public class Person
{
  public int Age {get;set;}
  public string Name {get;set;}

  public Person()
  {
  }
}

//Here the controller
public Controller PersonCreator
{
  public ActionResult CreatePerson()
  {
    //Posting from this page will go to SetPersonAge, as the name will be set in here.
    return View();
  }

  public ActionResult SetPersonAge(Person person)
  {
    //This should now have the name and age of the person
    return View(person);
  }
}

//Here is your SetPersonAge, which contains the name in the model already:
<%= Html.Hidden("Name", Model.Name) %>
<%Html.TextBox("Age") %>

.

+2

  • , javascript . , .

  • ( - ). . , , .

+1

MVC . , , , , - . , , , . cookie . Javascript 508, , . , . , , .

, , . , . , , / .

+1

ajax ( ) html5 ( ), , " ", ( ).

MVC WebForms , , ? , , AppFabric Windows Server ( , , , - ), . AppFabric , . , -.

+1

, , ( ), . .

, , : , , Session , , . - :

//Here the controller
public Controller PersonCreator  
{  
    public ActionResult CreatePerson()  
    {    
        //get the age out of the session
        int age = (int)(Session["age"]);
        //do something with it...
        return View();  
    }  
    public ActionResult SetPersonAge(Person person)  
    {  
        //put the age in the session
        Session.Add("age", person.Age);
        return View(person);  
    }
}

, , - .

0

ASP.NET MVC 2/3 MVC Futures. Google Books - , .

, . , .

, OnActionExecuting OnResultExecuted ( ), .

- , .

0

All Articles