Losing Session Variable

F

Frank Bishop

Can someone tell me why I'm losing my session variable when using
Response.Redirect? When I use the RedirectFromLoginPage method(currently
remmed out below), my session variable works fine, but I'm trying this
other way with Response.Redirect and it seems all my redirection works,
but it loses the session variable when I hit the redirected pages. Help
appreciated. Here is code:
<code>
<%@ Import Namespace="System.Data.OleDB" %>

<%@ Import Namespace="System.Web.Security " %>

<%@ Page Language="vb" CodeBehind="login.aspx.vb"
AutoEventWireup="false" Inherits="LoginWithSessionVariables.login" %>

<HTML>

<script language="VB" runat="server">

Sub Login_Click(Src As Object, E As EventArgs)

If Page.IsValid Then

Dim strConn as string ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=" & server.mappath("DB/WroxDBAuth.mdb") & ";"

Dim Conn as New OLEDBConnection(strConn)

Conn.Open()

Dim strSQL as string = "SELECT Pwd, Group FROM Tbl_MA_Users WHERE
Email = '" & txtEmail.Text & "'"

Dim Cmd as New OLEDBCommand(strSQL,Conn)

'Create a datareader, connection object

Dim Dr as OLEDBDataReader =
Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Dim strGroup As String

'Get the first row and check the password.

If Dr.Read()

If Dr("Pwd").ToString = txtPwd.text Then

strGroup = Dr("Group").ToString

'FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false)

FormsAuthentication.SetAuthCookie(txtEmail.Text, false)

Response.Redirect(strGroup)

Else

lblLoginMsg.text = "Invalid password."

End If

Else

lblLoginMsg.text = "Login name not found."

End If

Dr.Close

End If

Session("UserName") = txtEmail.Text

End Sub
</code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top