|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
BC30311: Value of type 'System.Web.HttpCookie' cannot be converted to 'String'.
Hi there
I am using forms authentication to restrict access to certain pages. The user is redirected to the login screen. The login screen uses the following code to create a cookie called UserId Code:
if dtrResults.Read()
System.Web.Security.FormsAuthentication.SetAuthCoo kie(Userid, True)
Response.Redirect("createanad.aspx")
else
What i need to do now is read this cookie and use the Userid from it to insert in to a database so the adverts created are associated with that user. Can anyone help me to read back the contents of the cookie and assign to a variable so i can insert it into the database This is what i have so far but it throws the above error in the subject Dim strULogin as string = Cstr(Request.Cookies("userid")) I am already checking to see if the user is authenticated at the top of the page and this seems to work. Just need to pass this value to my dataabse Any help would be great Paul |
|
#2
|
|||
|
|||
|
just realised....Please help
that allthough i am setting a cookie i am not inserting any particular values in it. I think that is called subkeys
I am trying to put the userid from my users table in the cookie. When when the user creates an advert the userid from this cokkie is inserted in the adverts table. Make sense Anyone no the systax for geeting a value from a database and inserting it into a cookie Here is my code Code:
Dim DBConn as OleDbConnection
Dim dtrResults as OleDBDataReader
Dim DSLogin as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "DATA SOURCE=" & Server.MapPath("data/Class.mdb;"))
DBConn.Open()
Dim CmdStr As String
Dim UseriD As String
Dim DBSelect As New OleDbCommand
CmdStr =("Select eMail, pass, UserID from tblUsers Where eMail =” & “@Email and pass = @Pass ")
DBSelect = new OleDbCommand(CmdStr, DBconn)
DBSelect.Parameters.Add("@email", OleDbType.VarChar, 255)
DBSelect.Parameters.Add("@Pass", OleDbType.VarChar, 255)
DBSelect.Parameters("@email").Value = txtEmail.text
DBSelect.Parameters("@Pass").Value = txtPass.text
dtrResults = DBSelect.ExecuteReader()
if dtrResults.Read()
System.Web.Security.FormsAuthentication.SetAuthCoo kie(Userid, True)
Response.Redirect("createanad.aspx")
else
lblmessage.text = "Sorry your eMail or password do not match our records. If you have forgotten your password <a href='ForgottenPassword.aspx'>click here</a>"
end if
end sub
Cheers for any help--please help |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > BC30311: Value of type 'System.Web.HttpCookie' cannot be converted to 'String'. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|