I am developing an e-Commerce site and I am using login control for users to login.
Once they login they can go to search page and search for products and go ahead with their purchase.
To make the payment I am using WorldPay. After the payment is completed, I want to redirect the users to
their purchased cart. But, the users are automatically logged out. They have to login again. I WANT TO KEEP THE USERS LOGIN DETAILS AND KEEP THEM LOGGED IN EVEN AFTER THE PURCHASE, UNTIL THEY CLICK ON Logout button.
I have given a web.config file inside Users folder, for extra securit and it has the following lines of code:-
Sometimes when I remove my web.config from my Users folder it is working.
But, I use this extra web.config for extra security.
How can I make the user keeps logged in even after the payment is completed
(when he is redirected from the WorldPay as well)?
Loading

Nipun TomarRank #90 · 23K reputationPosted May 11, 2009, 11:15 PM EDT
r pRank #4,639 · 333 reputationPosted May 13, 2009, 6:00 AM EDT
Nipun TomarRank #90 · 23K reputationPosted May 13, 2009, 8:00 PM EDT
First authenticate the user from database and then add a FormAuthentication ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket
(1, // Ticket version
UserName, // Username associated with ticket
DateTime.Now, // Date/time issued
DateTime.Now.AddMinutes(30), // Date/time to expire
false, // "true" for a persistent user cookie
HttpContext.Current.Session["UserType"].ToString(), // User-data, in this case the roles
FormsAuthentication.FormsCookiePath);
// add cookies
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
// Add the cookie to the list for outgoing response
HttpContext.Current.Response.Cookies.Add(cookie);
r pRank #4,639 · 333 reputationPosted May 14, 2009, 5:54 AM EDT
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 14: protected void Page_Load(object sender, EventArgs e) Line 15: { Line 16: FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Line 17: "myUserName", Line 18: DateTime.Now,