hi guys,
actually i searched this forum and find all suggestion as httpcontext.current.user.identity.name save it in session...
but i dont need it.because i should get userid login after he log in and store it as fk in another table as user_id field in database as int type.so Please help me ..i really need it. i used my login code that can control better things.u can see my code in login page.my login work correctly but when it go to another page after login i need in that page save user details as userid but its not possible for me because cmd.parameters.addwithvalue("user_id",i need sth hidden field here not txtbox or ddl)
using
System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Xml.Linq;
using
System.Data.SqlClient;
namespace
CMS
{
public partial class Loginn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cvlogin_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = checklogin();
}
private bool checklogin()
{
bool result = false;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cmsDBConnectionString2"].ConnectionString);
try
{
con.Open();
string sql = "select * from Users where Username=@Username and Password=@Password ";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue(
"Username", txtusername.Text);
cmd.Parameters.AddWithValue(
"Password", txtpass.Text);
result = cmd.ExecuteReader().HasRows;
}
catch (Exception exp)
{
Response.Write(
"<b>Error:</b>");
Response.Write(exp.Message);
}
finally
{
con.Close();
}
return result;
}
protected void btnlogin_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
FormsAuthentication.RedirectFromLoginPage(txtusername.Text,chkremember.Checked);
//FormsAuthentication.RedirectFromLoginPage(HttpContext.Current.User.Identity.ToString(),chkremember.Checked);
}
}
}
}