Hi friends..
I want to do from login authentication with sql server,cockies and ticket so pls help me to solve problem..
after checkin username and password not open athenticated aspx file.. username and password are correct still not opened.. i am using cockies and ticket method..
i think problem in web.config..
please help me.. Dost
This is code..
public partial class Login : System.Web.UI.Page
{
protected void BtnLogin_Click(object sender, EventArgs e)
{
try
{
if (IsValid)
{
SqlParameter[] parameterValues = new SqlParameter { SqlHelper.MakeParam("@LoginID", TxtLoginID.Text), SqlHelper.MakeParam("@Password", TxtPassword.Text) };
SqlConnection connection = null;
{
try
{
connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BESTConnection"].ConnectionString);
connection.Open();
SqlDataReader reader = SqlHelper.ExecuteReader(connection, "SP_AuthenticateInternalUsers", parameterValues);
{
if (reader.HasRows)
{
reader.Read();
string name = reader["Name"].ToString();
string userData = reader["InternalUserId"].ToString() + "|" + reader["AccessLevel"].ToString() + "|" + this.TxtLoginID.Text;
reader.Close();
connection.Close();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, DateTime.Now.AddMinutes(30.0), false, userData, FormsAuthentication.FormsCookiePath);
string str3 = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, str3));
Response.Redirect(FormsAuthentication.GetRedirectUrl(name,false),false);
}
else
{
LblMsg.Text = "Invalid Login ID or Password";
}
}
}
}
catch (Exception exception)
{
BESTPISUtilityClass.ShowException(this.Page, exception.Message.ToString());
}
}
}
}
catch (Exception exception2)
{
BESTPISUtilityClass.ShowException(this.Page, exception2.Message.ToString());
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Context.User.Identity.Name.Length > 0)
{
lblReason.Text = "<em>You do not have sufficient privilege to access the page that your were attempting to view.</em>";
}
else if (!string.IsNullOrEmpty(Request.QueryString["ref"]) && (Request.QueryString["ref"].ToLower() == "logout"))
{
lblReason.Text = lblReason.Text + "<em>You have logged out.</em>";
}
else
{
lblReason.Text = lblReason.Text + "<em>You are not currently authenticated.</em>";
}
}
}
}