Do I need to worry about session state?
Hi all hope you can help.
I am primarily a windows developer (winforms and wpf/mvvm) and it's been 10 years since my last web application, so this is probably a daft question.
I have just redeveloped a customer satisfaction questionnaire and as I had to figure out this from scratch thought I would use MVC 3 and Razor.
The Questionnaire is a single page web site with a controller that looks something like this.
Function Index(BrandName As String, CaseID As Integer, EventID As Integer) As ActionResult
ViewData("Scores") = Scores
Dim questionnaire As New Questionnaire
questionnaire.CaseID = CaseID
questionnaire.EventID = EventID
questionnaire.BrandName = BrandName
//Get Some specific branding from the database
questionnaire.FullBrandName = "FullNameFromDatabaseTable"
Return View(questionnaire)
开发者_StackOverflow中文版End Function
Function Save(questionnaire As Questionnaire) As ActionResult
If TryUpdateModel(questionnaire) Then
SaveQuestionnaireToDatabase(questionnaire)
Else
Return RedirectToAction("Index")
End If
Return View()
End Function
I have stripped out some database code and some stuff to get a signed image url as i don't think its relevant.
I am not sure I fully understand the magic that is happening between view and controller which is the real reason for my question.
This is going up into azure along with everything else, I am asking the question about session state because this will be load balanced accross two instances. No authentication is required to access the page as it can only be completed once.
Many Thanks
p.s I couldn't get vb style quotes to work so put in the c# one.
It doesn't look like you are doing anything that touches the session, so there's no concern about which server the post goes to. All the information to process the request is submitted with the form.
You can take a look here (specifically section titled Implementing Add New Product ) to remove some of the mystery of how form data is mapped back to server side information.
If you have any content that needs to be shared / accessed across instances, simply use the AppFabric Cache, which went live about two weeks ago. I provided a link in this SO answer. The nice thing is that you can use the cache provider with just a few lines of code to set up, then call Put() and Get() for serializable key/value pairs. When you set up the cache, you can also enable a custom asp.net session state provider with a simple web config change - the Azure portal will auto-generate the xml for you.
精彩评论