Hello, m using c# .asp.net and oracle databse.
I’ve been trying to expire the session after the user logs out of my site. I have a “logout” button in the site. Is there any way I could make the user unable to go back to the page without logging in again after clicking the logout button. After clicking on logout m redirecting to login page…
what and where to write for this.
Please help.
In logout.aspx page, write the following code :
Session.Clear();
Session.Abandon();
Response.Redirect(“Login.aspx”,true);
It’s working but in some forms m getting error.
object reference not set to an instance of an object.
This error is coming on the pages where m using session in page_load event.
like i have one form addsubcategory.aspx.
In that i have written d following code.
Do read commented line.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
// btnAdd.Attributes.Add("onclick", "return Validate('" + ddlCategory.ClientID + "','" + ddlSeverityType.ClientID + "')");
//btnAdd.Attributes.Add("onclick", "javascript:return isNumeric();");
//btnAdd.Attributes.Add("onclick", "return isNumeric('" + txtSubcategoryName.ClientID + "','" + ddlCategory.ClientID + "')");
btnAdd.Attributes.Add("onclick", "return Valid('" + txtSubcategoryName.ClientID + "','" + ddlCategory.ClientID + "','" + ddlSeverityType.ClientID + "')");
txtSubcategoryName.Focus();
BLSubcategory objSubcategory = new BLSubcategory();
string supId = string.Empty;
supId = Session["USERNAME"].ToString();//here m getting error
dsCategory = objSubcategory.GetCategory(supId);
dsSeverity = objSubcategory.GetSeverity(supId);
DataRow dr = dsCategory.Tables[0].NewRow();
DataRow dt = dsSeverity.Tables[0].NewRow();
dr["Category_Name"]= "Select Category";
dr["Category_Id"] = "0";
dsCategory.Tables[0].Rows.InsertAt(dr, 0);
ddlCategory.DataSource = dsCategory;
ddlCategory.DataTextField = "Category_Name";
ddlCategory.DataValueField = "Category_Id";
ddlCategory.DataBind();
dt["Severity_Type"]="0";
dt["Severity_Id"] = "0";
dsSeverity.Tables[0].Rows.InsertAt(dt,0);
ddlSeverityType.DataSource = dsSeverity;
ddlSeverityType.DataTextField = "Severity_Type";
ddlSeverityType.DataValueField = "Severity_Id";
ddlSeverityType.DataBind();
}
catch (Exception ex)
{
throw ex;//here it says object ref not set to an instance of an obj.
}
LoadSubcategory();
}
}
Hi,
I have a “logout” button in the site.
On logout button click event you have to write
Session.Clear();
Session.Abandon();
Response.Redirect(“Login.aspx”,true);
thanks,
kunalraj
Are you using forms authentication? If so, do it like this:
Session.Clear();
Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect(“Login.aspx”);
It’s working…thanks.