Forum Moderators: open

Message Too Old, No Replies

Session and Data

         

NoSkills

12:55 am on Jul 18, 2005 (gmt 0)

10+ Year Member



I'm having a huge problem that will probably be a no brainer for most of you. I'm creating a loggin page that after checking the if the username and password match, its saves the username to session("username") then redirects the user to a menu. I need to some how get the User's ID # into a session("userID"). This is what I have tried.

<form name="form1" runat="server">
<input name="userID" type="hidden" value="
<%# DataSet1.FieldValue("auto_ID", Container) %>">
<% Session("registerID") = request.Form("userID")%>
</form>

And also tried

<script runat="server">
sub Page_Load(obj as object, e as eventArgs)
Session("userID") = "<%# DataSet1.FieldValue('auto_ID', Container) %>"
end sub
</server>

Please help!

NoSkills

1:02 am on Jul 19, 2005 (gmt 0)

10+ Year Member



Please help! I'm basiclly asking to how to get a piece of info out of my data base and into a session... Any help?

theleveller

2:09 pm on Jul 19, 2005 (gmt 0)

10+ Year Member



Im sure the session varibles should be straight foward instead of the cookies in this example..

strUserName = Request.form("strUserName")
strPassword = Request.form("strPassword")

set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString

sqlText="SELECT * FROM admindatabase WHERE username='"&strUserName &"'"
set rsUser = Conn.Execute(sqlText)
if rsUser.EOF then
'No such username, so the recordset is empty
Response.Redirect "Login.asp?retry=username"
else
'The username is good, let's check the password
realPassword = trim(rsUser("password"))

if strPassword = realPassword then
'Password is good, too
Response.cookies("isLoggedInAs")("username") = strUserName
Response.cookies("isLoggedInAs")("fName")= rsUser("fName")
else
'Username is good, but password is wrong
Response.Redirect "Login.asp?retry=password"
end if
end if

loggedinas = strUserName
strname = rsUser("username")
strgroup = rsUser("group")
menu = rsUser("menu")
rsUser.Close
set rsUser = Nothing
Conn.Close
set Conn = Nothing

Response.Redirect menu

hope that helps..

aajiz

9:04 pm on Jul 19, 2005 (gmt 0)

10+ Year Member



Are you using ASP.Net? There are easier ways to save and read session data. Can you post a complete section of your code?

NoSkills

5:51 am on Jul 20, 2005 (gmt 0)

10+ Year Member



Yes I'm using VB.Net in Dreamweaver. I can get a value out of a form, but not directly from the database to a session value.

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="DataSet1"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_rb_db") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_rb_db") %>'
CommandText='<%# "SELECT * FROM tblRegistry WHERE username =?" %>'
Debug="true"
>
<Parameters>
<Parameter Name="@username" Value='<%# IIf((Not Session("username") Is Nothing), Session("username"), "") %>' Type="WChar" />
</Parameters>
</MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">royal baby wear - contact info</div></td>
</tr>
<tr>
<td><div align="center">
<p> <br>
<%# DataSet1.FieldValue("firstName", Container) %>
<%# DataSet1.FieldValue("lastName", Container) %>
<br>
<%# DataSet1.FieldValue("addressDB", Container) %>
<br>
<%# DataSet1.FieldValue("cityDB", Container) %>
,
<%# DataSet1.FieldValue("stateDB", Container) %>
<%# DataSet1.FieldValue("zipDB", Container) %>
</p>
<p>
<%# DataSet1.FieldValue("phoneDB", Container) %>
ID:
<%# DataSet1.FieldValue("auto_ID", Container) %>
</p>
<form name="form1" runat="server">
<input name="userID" type="hidden" value="<%# DataSet1.FieldValue("auto_ID", Container) %>">
<% Session("registerID") = request.Form("userID")%>
</form>
<p><a href="catagory.aspx">Continue </a></p>
</div></td>
</tr>
</table>
</body>
</html>

noghte

5:22 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



Are userID and username same?
I'm confused!
What's wrong with this line?
<% Session("registerID") = request.Form("userID")%>

Would you please explain more what you want to do?

NoSkills

6:00 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



no.. This is what this page is doing... Its calling the user's info from the data base WHERE the username = username from the form on the previos page. the AutoID is the user's data base number that I want to put into a session value. The <% Session("registerID") = request.Form("userID")%> doesn't seem to be working

NoSkills

6:24 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



This is ultimatly what I would like to do but this doesn't seem to work.

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="DataSet1"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_rb_db") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_rb_db") %>'
CommandText='<%# "SELECT * FROM tblRegistry WHERE username =?" %>'
Debug="true"
>
<Parameters>
<Parameter Name="@username" Value='<%# IIf((Not Session("username") Is Nothing), Session("username"), "") %>' Type="WChar" />
</Parameters>
</MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />

<script runat="server">
sub Page_Load(obj as object, e as eventArgs)
Session("userID") = "<%# DataSet1.FieldValue('auto_ID', Container) %>"
response.Redirect("catagory.aspx")
end sub
</script>

aajiz

4:35 am on Jul 21, 2005 (gmt 0)

10+ Year Member



You can't use binding within the code. Try the modified code below:

<script runat="server">
sub Page_Load(obj as object, e as eventArgs)
If Not IsPostBack Then
Session("userID") = DataSet1.FieldValue('auto_ID', null)
response.Redirect("catagory.aspx")
End If
end sub
</script>

NoSkills

5:58 am on Jul 21, 2005 (gmt 0)

10+ Year Member



Thanks for the help but the same error comes up with the null as it did with the container.

this is the error

BC30822: 'null' is not declared. 'Null' constant is no longer supported; use 'System.DBNull' instead.

aajiz

4:22 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



My bad. I used null which works in C#. Try the keyword "Nothing" without the quotes instead.