开发者

Session and Tabbed Browsing ASP.Net MVC

开发者 https://www.devze.com 2023-01-31 05:32 出处:网络
I\'m once again looking into the world of tabbed browsing and Sessions. Looking over a few google searches it seems that there isn\'t a nice way of supporting this.

I'm once again looking into the world of tabbed browsing and Sessions. Looking over a few google searches it seems that there isn't a nice way of supporting this.

Does anyone know of a method that allows Bookmarking without stealing a session (cookieless) (and this doesn't work in MVC2 for dataannotations).

Supporting tabs in such a way that it's per use case (like Windows Workflow), going through two workflows at once.

I'm thinking a url in the query string might support thi开发者_StackOverflows, but I'm wondering if anybody else has done a similar implementation.

[Edit] Use Case: Say I'm writing an application that uses something like Windows Workflow. Each UI workflow may do an action such as collect settings of a page and execute some external process. I may wish to do two of these workflows at once (not necessarily the same UI workflow). As such if I saved in session I would get:

a) Different tabs interfering with the workflow b) Previous/Next buttons would be extremely difficult to work out, due to a).

I would like it so either, a user cannot open another tab to a url (don't think there is a 100% method of preventing this), or allow a user to use a UI workflow in isolation without one affecting another (much like running two workflows in two different browsers).

Hopefully that gives an indication of what I'm attempting to do.

Regards, J


It sounds like you might be trying to do the following:

For example, let's say you have a two page questionaire, the first page has first name on it and the second page has last name on it. You desire that the user can open two tabs, and be at different pages in the questionaire while entering different data in the questionaire in each tab.

So in Tab A, you have entered Mark as the first name and submitted and you are at page two now in Tab A. You decide you are going to do a questionairre for your friend also, so you open up a new Tab, Tab B. In Tab B you enter Tom and submit the page.

Currently in the browser you have Tab A, which is at page 2 of the questionaire with firstname = "Mark" and Tab B which is at page 2 of the questionaire with first name = "Tom". Assuming you wanted to maintain both of these in session on the server here is an approach that i think will work for you.

When a web browser requests page 1 of your form, on a GET request(no posted questionaire data to the server), you supply a hidden field in the the response html and generate a random number to store in that field. When this form is submitted you do the following on the server:

  1. Look in session using the random number as a key "var questionaire = session[Request.Form["questionaire_rnumber"]]
  2. if the questionaire is not in session you create a new questionaire and update it's properties and stick it in session

    var questionaire = new Questionaire();
    questionaire.FirstName = Request.Form["firstName"]
    session[Request.Form["questionaire_rnumber"]] = questionaire;

if the questionaire was in the session you simply update the object, and display the next page, however when you display the next page you will want to supply the hidden random number field in the html again, using the same random number you used on page 1.

This way you can hold any number of questionaires in a single session. With MVC.NET it should be straight forward for you to add the random number field to your view model and add the logic for looking in session for an existing questionaire or creating a new one and I think you'll be good to go.

You should keep in mind the possible issues with the approach also, like back button issues, security issues, and performance issues.

One example of a security and a performance issue would be that an attacker realizes your application works like this and the attacker requests page 1 of your form 10,000 times and submit the page 1 each time. You would have 10,000 questionaire objects in that one user session. If the attacker deleted his session ID cookie 10,000 times and for each session id cookie he created 10,000 requests for page 1 and submitted the page 1 form, you would have 100,000 questionaire objects cumulatively across 10,000 sessions on your server. So you should put some constraints on it also to protect your application, for example:

  1. Any individual session can only have X questionaires in session
  2. Any individual IP address can only have Y concurrent sessions (this you would probably need to track in the Application object)

ADDITIONAL RESPONSE TO ADDED USE CASE

Thanks for the use case. My solution should still work for you. You have two options.

If you want to ensure there is only one tab working with your workflow, then when the random number is passed to the server from a new tab you will be able to detect that there is another workflow in progress and that the random number from the new tab does not match the random number from the first, so you will throw an exception and show the user some messaging that says they can't start a new workflow until they finish the first one, and ask if they want to cancel the first. You have to ask if they want to cancel it because if they close their browser on the first workflow they started they will be stuck until their session expires. Which won't happen if they keep trying to start a new workflow.

Secondly, you could allow them to do multiple, but segment the context of each workflow by the random number, as suggested in the first answer. The whole point is that you are making little mini-sessions in your session, but keyed of a value that is only stored in the client. So since each tab has a different random number when the form posts to the server, it's easy to correlate that random number with an entry in your session that has all the information about the workflow initiated from that tab.

Hope this helps.


You need to store wizard state information in the client in some way, via query string or form values. As you've intuited, Session will not work. Nor will anything else that relies solely on what is on the server.

0

精彩评论

暂无评论...
验证码 换一张
取 消