I'm getting error like
An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Session.get'
Can you suggest me to recover from this problem in session.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.SessionState;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//Onclick Submit Button
[WebMethod(EnableSession = true)]
//[System.Web.Services.WebMethod(EnableSession = true)]
public static string Login(string email, string password)
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["blogConnString"].ConnectionString);
con.Open();
string res = "0";
SqlDataReader reader;
string sql = "select uid,username from personal where email='" + email + "' and password='" + password + "'";
SqlCommand cmd1 = new SqlCommand(sql, con);
reader = cmd1.ExecuteReader();
while (reader.Read())
{
res = "1";
Session["UID"] = reader["uid"].ToString(); //error line here
Session["UNAME"] = reader["username"].ToString(); //error line here
}
return res;
con.Close();
}
}
parameterized queries
. This kind of string concatenations are open forSQL Injection
attacks. And useusing
statement to dispose yourSqlConnection
,SqlCommand
andSqlDataReader
. – Coraleecoralie