Harish Batchu

Harish Batchu

  • NA
  • 255
  • 70.2k

I need to create session inside of the webmethod?

Oct 25 2018 5:32 AM
I have one method inside class in that class i have one webmethod there i need to create session variable 
 
public partial class Incomeexpenses : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod (EnableSession =true)]
[ScriptMethod]
public static string SaveDetails(string Name, string Password)
{
Util u = new Util();
try
{
string ip = u.GetIP();
SqlCommand cmd;
SqlConnection con = new SqlConnection();
SqlDataReader dr;
con = u.GetConnection();
cmd = new SqlCommand("select User_Uniq from Dim_Users where User_Email='" + Name + "'", con);
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
//here i need to create session variable  
Session["UserName"] = dr.GetString(0).ToString();
con.Close();
return "true";
}
else
{
con.Close();
return "false";
}
}
catch (Exception ex)
{
throw ex;
}
}
 }

Answers (2)