Regarding page direct for login page

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Can anyone please let me know?
Below is my code for login. Can anyone please suggest me how to redirect to another page based on the user and if not then redirect to another page.I know we can use roles and do it but right now we dont have that one.
using System;<br/>
using System.Data;<br/>
using System.Configuration;<br/>
using System.Collections;<br/>
using System.Web;<br/>
using System.Data.Linq;<br/>
using System.Web.Security;<br/>
using System.Web.UI;<br/>
using System.Web.UI.WebControls;<br/>
using System.Web.UI.WebControls.WebParts;<br/>
using System.Web.UI.HtmlControls;<br/>
<br/>
public partial class Logging_In : System.Web.UI.Page<br/>
{<br/>
public MembershipUser loginUser;<br/>
public string cLine;<br/>
protected DateTime expiration = DateTime.MinValue;<br/>
<br/>
private const string ApplicationName = "Issues Tracker";<br/>
private const string ApplicationUser = "";<br/>
<br/>
//public MembershipUser usrInfo = Membership.GetUser(Login1.UserName);<br/>
<br/>
protected void Page_Load(object sender, EventArgs e)<br/>
{<br/>
<br/>
/*MembershipUser usrInfo = Membership.GetUser(loginUser.UserName);<br/>
<br/>
loginUser = Membership.GetUser(Login1.UserName);<br/>
<br/>
<br/>
<br/>
if (loginUser.UserName == "holland_user")<br/>
{<br/>
<br/>


<br/>
cLine = this.ViewState["Hal"].ToString();<br/>
<br/>
}*/<br/>
<br/>
<br/>
/* Response.AddHeader("pragma", "no-cache");<br/>
<br/>
Response.AddHeader("cache-control",<br/>
"private");<br/>
<br/>
Response.CacheControl = "no-cache";<br/>
<br/>
Response.Cache.SetExpires(DateTime.Now.AddMinutes(-1));<br/>
<br/>
Response.Cache.SetCacheability(HttpCacheability.NoCache);<br/>
<br/>
Response.Cache.SetNoStore();<br/>
<br/>
Context.Items["objData"] = new object();<br/>
object ob =Context.Items["objData"];
<br/>
*/<br/>
}<br/>
/*protected void On_Load(object sender, EventArgs e)<br/>
{<br/>
<br/>
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));<br/>
// FormsAuthentication.RedirectFromLoginPage(this.loginUser.UserName, false);<br/>
<br/>
Response.Cookies.Clear();<br/>
Response.End();<br/>
Session.Abandon();<br/>
Session.Clear();<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
}*/<br/>
protected void Page_Unload(object sender, EventArgs e)<br/>
{<br/>
<br/>
<br/>
<br/>
}<br/>
protected void Login1_LoggedIn(object sender, EventArgs e)<br/>
{<br/>
<br/>
<br/>
if (loginUser == null)<br/>
loginUser = Membership.GetUser(Login1.UserName);<br/>
<br/>
//DetermineExpirationForNewLogin();<br/>
<br/>
//represents the active login "session"<br/>
Guid g = System.Guid.NewGuid();<br/>
<br/>
HttpCookie c = Response.Cookies[FormsAuthentication.FormsCookieName];<br/>
FormsAuthenticationTicket ft = FormsAuthentication.Decrypt(c.Value);<br/>
<br/>
//Generate a new ticket that includes the login session ID<br/>
FormsAuthenticationTicket ftNew =<br/>
new FormsAuthenticationTicket(<br/>
ft.Version,<br/>
ft.Name,<br/>
ft.IssueDate,<br/>
ft.Expiration,<br/>
ft.IsPersistent,<br/>
g.ToString(),<br/>
ft.CookiePath);<br/>
<br/>
Session.Add("itsthem", ft.Name);<br/>
Session["OOname"] = ft.Name;<br/>
<br/>
Session["OOname1"] = this.loginUser.UserName.ToString();<br/>
Session["UserEmail"] = null;<br/>
Session["UserEmail"] = this.loginUser.Email.ToString();<br/>
// Session["NameofUser"] = this.loginUser.<br/>
<br/>
//Store the expiration date and login session ID in Membership<br/>
loginUser.Comment =<br/>
"LoginExpiration;" + ft.Expiration.ToString() +<br/>
"|LoginSessionID;" + g.ToString();<br/>
Membership.UpdateUser(loginUser);<br/>
<br/>
//Re-issue the updated forms authentication t;icket<br/>
Response.Cookies.Remove(FormsAuthentication.FormsCookieName);<br/>
<br/>
//Basically clone the original cookie except for the payload<br/>
HttpCookie newAuthCookie =<br/>
new HttpCookie(<br/>
FormsAuthentication.FormsCookieName,<br/>
FormsAuthentication.Encrypt(ftNew));<br/>
newAuthCookie.HttpOnly = c.HttpOnly;<br/>
newAuthCookie.Path = c.Path;<br/>
newAuthCookie.Secure = c.Secure;<br/>
newAuthCookie.Domain = c.Domain;<br/>
newAuthCookie.Expires = c.Expires;<br/>
<br/>
//And set it back in the response<br/>
Response.Cookies.Add(newAuthCookie);<br/>
<br/>
}<br/>
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)<br/>
{<br/>
if (loginUser == null)<br/>
loginUser = Membership.GetUser(Login1.UserName);<br/>
//See if the user indicates that they want an existing login session<br/>
//to be forcibly terminated<br/>
CheckBox cb = (CheckBox)Login1.FindControl("ForceLogout");<br/>
if (cb.Checked)<br/>
{<br/>
loginUser.Comment = String.Empty;<br/>
Membership.UpdateUser(loginUser);<br/>
return;<br/>
}<br/>
<br/>
// if (loginUser != null && loginUser.Comment.Contains("Issues tracker"))<br/>
if (loginUser != null) <br/>
{ <br/>
DataUtiliities dataUtilities = new DataUtiliities("wmsweb"); <br/>
DataSet dsApplications = dataUtilities.ExecuteDataSet("select ac.ItemName as [desc],ugl.UserID," + <br/>
" ac.ConfigurationID as value,ac.Value1 as [ExtValue1],ac.ApplicationName,ac.Configurationcategory, ac.Value2 as [ExtValue2],ac.Value3 as [ExtValue3],ac.Value4 as [ExtValue4],ac.Value5 as [ExtValue5],ac.Value6 as [ExtValue6],ac.ConfigurationID" + <br/>
" from UsersGroupsLK ugl" + <br/>
" inner join GroupApplicationConfigurationslk gacl on gacl.groupnumber = ugl.groupnumber" + <br/>
" inner join ApplicationConfigurations ac on ac.configurationid = gacl.configurationid" + <br/>
" inner join [Users] u on ugl.UserID = u.UserID" + <br/>
" where ugl.UserID = " + Login1.UserName + " and ac.ApplicationName = Issues Tracker and ac.Configurationcategory = Turnover Shift"); <br/>
<br/>
if (dsApplications.Tables[0].Rows.Count > 0) <br/>
{ <br/>
Session["ApplicationName"] = dsApplications.Tables[0].Rows[0]["ApplicationName"].ToString(); <br/>
Session["UserID"] = dsApplications.Tables[0].Rows[0]["UserID"].ToString(); <br/>
} <br/>
<br/>
Response.Redirect("~/Tor Tool/Default.aspx");<br/>
<br/>
<br/>
}<br/>
else<br/>
{<br/>
<br/>
//Only need to check if the user instance already has login information<br/>
//stored in the Comment field.<br/>
if (loginUser == null)<br/>
{<br/>
Response.Write("Invalid Password");<br/>
wrongID.Text = "You have entered invalid login information";<br/>
<br/>
//FormsAuthentication.SignOut();<br/>
Response.Redirect("Logging_In.aspx");<br/>
}<br/>
<br/>
if (!String.IsNullOrEmpty(loginUser.Comment) && loginUser.Comment.Contains("LoginExpiration"))<br/>
{<br/>
string currentExpirationString =<br/>
loginUser.Comment.Split("|".ToCharArray())[0];<br/>
DateTime currentExpiration = DateTime.Parse((currentExpirationString.Split(";".ToCharArray()))[1]);<br/>
<br/>
//The user was logged in at some point previously and the login is still<br/>
//valid<br/>
if (DateTime.Now <= currentExpiration)<br/>
{<br/>
e.Cancel = true;<br/>
Literal tx = (Literal)Login1.FindControl("FailureText");<br/>
tx.Text = "You are already logged in.";<br/>
Response.Redirect("~/SatReport_Container.aspx");<br/>
//Response.Redirect("~/Tor Tool/Default.aspx");<br/>
<br/>
}<br/>
}<br/>
}<br/>
<br/>
}<br/>
protected void LoggedOutof(object sender, EventArgs e)<br/>
{<br/>
// Response.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddMonths(24);<br/>
System.Web.Security.FormsAuthentication.SignOut();<br/>
FormsAuthentication.RedirectToLoginPage();<br/>
<br/>
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));<br/>
//FormsAuthentication.RedirectFromLoginPage(this.loginUser.UserName, true);<br/>
ViewState["Liner"] = "";<br/>
Response.Cookies.Clear();<br/>
Response.End();<br/>
Session.Abandon();<br/>
Session.Clear();<br/>
Session.RemoveAll();<br/>
// Response.Redirect("/SatReport_Container.aspx");<br/>
Response.Redirect("~/Default.aspx");<br/>
}<br/>
}

In the above code the bold part is where i am stuck,i want to be able to check if the user is from that application then redirect them to
"Response.Redirect("~/Tor Tool/Default.aspx");" else "("/SatReport_Container.aspx")".Please help me.I am new to c#.

Thanks!! <hr class="sig rr

View the full article
 
Back
Top