views:

54

answers:

3

I have a large webform, and would like to prompt the user to login if their session expires, or have them login when they submit the form. It seems that having them login when they submit the form creates alot of challenges because they get redirected to the login page and then the postback data for the original form submission is lost.

So I'm thinking about how to prompt them to login asynchrounsly when the session expires. So that they stay on the original form page, have a panel appear telling them the session has expired and they need to login, it submits the login asynchronously, the login panel disapears, and the user is still on the original partially filled form and can submit it. Is this easily doable using the existing ASP.NET Membership controls? When they submit the form will I need to worry about the session key? I mean, I am wondering if the session key the form submits will be the original one from before the session expired which won't match the new one generated after logging in again asynchrounously(I still do not understand the details of how ASP.NET tracks authentication/session IDs).

Edit: Yes I am actually concerned about authentication expiration. The user must be authenticated for the submitted data to be considered valid.

+1  A: 

There are many ways of doing this: you may store a cookie on the user's computer, or you can also split the form into smaller forms (i.e.: step 1 - enter your personal information, step 2 - enter billing info, etc.).

Splitting your form makes it faster for a user to enter the data, thus reducing the chances for their session to expire.

Adding a cookie to this makes it so that the person's information is still there, even if you log in afterwards. Just make sure to unset these said cookies at the end.

Christopher Richa
This is the best solution. If your form is so big users are having authentication time outs, you need to improve the UI. This method is also easily implemented.
Bryan
@Bryan I agree breaking the form up is a possibility, but I disagree that it is the best solution as this means I need to stage the partially completed data in the database with a flag indicating the user hasn't officially submitted it yet, which is important for meeting business requirements. Additionally this doesn't solve all scenarios. A form can be small and still have a timeout resulting from a user switching to a different application if they got sidetracked, got a phone call, or went to the bathroom.
AaronLS
That's why you stage it in the DB or put it in cookie like Christopher suggests. :)
Bryan
+2  A: 

Session expiration is different than authentication expiration - you probably need to determine which you are concerned about.

Sessions expire after 20 minutes of inactivity (by default), and will clear the Session object. When it expires, anything you stashed into Session will be gone.

[Forms] Authentication expires after 30 minutes of inactivity (by default) - though it's only updated every half-life. So, in reality - it can expire after 15 minutes of inactivity (by default). When it expires, the next request will be redirected to your login page.

Session and Authentication aren't really related - you can be an anonymous (non-authenticated) user, and still have a Session - or you can be logged-in (authenticated) but not have a Session. Your Session could expire before your authentication does, or vice-versa.

You could simply crank up the values for expiration for Session and/or Authentication. The problem with Session is that it chews server resources, and keeping Authentication is a security problem.

If you're just concerned about keeping them both alive for the duration of your form, a small bit of JavaScript that hits a server page with XmlHttpRequest or an iframe will reset the expiration for both (because of slidingExpiration).

There's other techniques as well, but it'd be helpful to better define the issue first.

Mark Brackett
@Mark Thanks, You are right in that I am concerned about authentication, not really the session, as the user must be logged in to submit the data. I do not want to keep the sessions alive longer than usual. I do want the login to timeout as normal, but the data is not sensitive, so we can leave the form up and ask the user to login when they "come back" to the computer and want to finish and submit the form.
AaronLS
+1  A: 

Very nice response @Mark Brackett reading the OP's comment below I believe this is his end goal.

On the button / submit element you want to write a javascript method that via ajax will poll the server to see if they are still authenticated.

If they are auth'd still you want to return true and let the form do it's regular submission, if it returns false you want to not allow the form to submit. At this point you will want to use javascript to display either a "window" inside the browser (think floating div) or to pop up a true new window for them to log in (I'd recommend the first method) that this new window will allow them to login via ajax and then hide/close itself.

Then with that window gone when they click the submit button again they will be able to successfully post the form.

Chris Marisic
@Chris Thanks, this is exactly what I was trying to describe. So the two questions I posed regarding this are: Is this easily doable using the existing ASP.NET Membership controls? When they submit the form will I need to worry about the session key?
AaronLS
It should be manageable. (it's possible you could need to write a custom membership provider since by default alot of it wants to redirect for stuff, it's been a while since i've worked with them so I'm hesitant that I might misspeak on it) I don't think you will need to worry about the session except if you store data that the form needs to submit you will need to be able to figure out how to repopulate that when they login.
Chris Marisic