I am trying to clear session variables after I have logged out. In my search.aspx I have a logout button therefore I put the below code in search.aspx.vb. However it does does seem to work.

Protected Sub hlLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles hlLogout
       {



        if(Session["User Name"]!=null) Session.Remove("User Name");
          if(Session["Password"]!=null) Session.Remove("Password");          


  Response.Redirect("Default.aspx");
       }

As I am new to sessions etc. I am not even show if I have put it in the right place, or if I need more code elsewhere in my application. Could anyone help me with this issue?

Thank you

Recommended Answers

All 7 Replies

You can just abandon the section using: session.abandon

Where should I place this code?

In your code replace

if(Session["User Name"]!=null) Session.Remove("User Name");
if(Session["Password"]!=null) Session.Remove("Password");

with

Session.Abandon();

I receive this error below:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30287: '.' expected.

Source Error:

Line 23: End Sub
Line 24:
Line 25: Protected Sub hlLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles hlLogout
Line 26: {
Line 27:


Source File: E:\VB Help Guide work\Users\Search.aspx.vb Line: 25

I am assuming I have placed it in the wrong place, or I have written the code wrong

You are using VB.Net or C#?

@ first glance, I didn't noticed it.
The code

Protected Sub hlLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles hlLogout

is VB.Net and the code

{

if(Session["User Name"]!=null) Session.Remove("User Name");
if(Session["Password"]!=null) Session.Remove("Password");

Response.Redirect("Default.aspx");
}

is C#.

Basically What I want to do is. If someone copies the url into a new tab a want it to log the person out. I heard that is called session destroy!

The second thing is if somone logged out, it would take them to the logged out page, then clicked on the back icon it takes them back to the logged in page. What is the best way to avoid both these?

Your error

Source File: E:\VB Help Guide work\Users\Search.aspx.vb Line: 25

says that it is VB.Net

Before you start programming, it is necessary to know the basic syntax of that language.

I suggest you to learn these things first.
About .Net
* What is .Net
* What are the different types of applications that you can write in .Net
* What are the languages it supports.
* Basic syntax of the language that you are using.

About Programming
* What is variables, conditions, loops etc...
* What is Procedural programming and what is OOPs? , difference b/w these.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.