asked on
void CreateUserTicket(short userId, bool rememberMe, string userName, string application)
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
Convert.ToString(userId),
DateTime.Now,
DateTime.Now.AddDays(30),
rememberMe,
UserProfileBLL.GetUserRoles(userName, application),
FormsAuthentication.FormsCookiePath);
// Encrypt the cookie using the machine key for secure transport
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie authCookie = 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)
{
authCookie.Expires = ticket.Expiration;
}
// Add the cookie to the list for outgoing response
Response.Cookies.Add(authCookie);
UserProfile userProfile = UserProfileBLL.GetUserProfile(userId);
HttpCookie userInfoCookie = new HttpCookie("UserInformation");
userInfoCookie.Values.Add("FirstName", userProfile.FirstName);
userInfoCookie.Values.Add("LastName", userProfile.LastName);
userInfoCookie.Values.Add("Email", userProfile.Email);
userInfoCookie.Values.Add("App", application);
userInfoCookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(userInfoCookie);
}
void RequestLogin()
{
// Redirect to requested URL, or homepage if no previous pagerequested
string returnUrl = this.Request.QueryString["ReturnUrl"];
if (returnUrl == null) returnUrl = ResolveUrl("~/Default.aspx");
// Don't call FormsAuthentication.RedirectFromLoginPage since it
// could replace the authentication ticket (cookie) we just added
Response.Redirect(returnUrl);
}
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
RequestLogin();
}
else
{
((Literal)Master.FindControl("liLoginStatus")).Visible = false;
((ComponentArt.Web.UI.Menu)Master.FindControl("Menu1")).Visible = false;
}
}
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
ASKER
This is why I have implemented a separate redirect logic. I have seen numerous posts on the Web regarding this issue.