SQL Server 2000 Developer won't write my cookie

Status
Not open for further replies.

StanGable

Ars Legatus Legionis
18,817
This is related to a question I asked a week ago (or so)...

I have a simple page that writes a cookie:

response.cookies("meathead")=objRS("securitylevel")

with a successful login. It wouldn't work here at home so I set IE to prompt for each cookie- I am not prompted, so I don't think the server (SQL2000 Developer) is trying to write it. It has worked just fine at work running on SQL7 and SQL2K servers, just not here at home.

Another difference that just occurred to me is that I am using 'trusted_connection=yes' here (it's the only fucking way I can get past the 'not associated with a trusted sql server' error). Might this be a problem?

Any ideas? TIA-rodbac
 

StanGable

Ars Legatus Legionis
18,817
Thanks a lot for the replies.

The only reason I posted any code at all was to show the method I was using to write the cookie. I didn't think you guys wanted to pore over my logic because, like I said, I know the code works.

That said, it turns out the cookie is indeed being written (I thought I knew where they were stored-- where the hell are they stored?), as I can display the cookie and db info. The problem is that the page it's redirecting to is not reading it. Here's the code:

*********From the login page:************

Dim objUserName, objPassword

objUserName = Request.Form("UserName")
objPassword = Request.Form("Password")

If Request.Form("Submit") = "Cancel" Then
Response.Redirect "../index.asp"
Else

If objUserName <> "" then

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "SELECT * FROM tblUserInfo WHERE UserName = '" & objUserName & "' AND Password = '" & objPassword & "'", objConn,1,2

If not objRS.EOF then

Session("TryCount") = 0
Response.Cookies("MatUser") = objRS("FullName")
Response.Cookies("MatSecurity") = objRS("SecurityLevel")

If objRS("RequireUpdate") = "y" then
Response.Redirect "update.asp"
Else
Response.redirect "../formbrowser.asp"
'Response.Write Request.Cookies("MatUser")
'Response.Write Request.Cookies("MatSecurity")
End if

Else
strMessage = "You did not enter a valid password"
Session("Trycount") = Session("TryCount") + 1
Response.Cookies("MatSecurity") = ""

End if

End if
*******************************************

*********From the redirect page:***********

Dim V, user_name
V= Request.Cookies("MatSecurity")
If V = "" Then
session("from_url")=Request.ServerVariables("URL")
Response.redirect "login/verify.asp"
else
user_name = Request.Cookies("matUser")
end if

*******************************************

This is the only code on the page that would redirect back to login.asp. Why TF is V coming out equal to "" when it should be "n"??? Thanks for helping me out. -rodbac

edit-PS- This code works on three different servers at work running both IIS4/SQL7 and IIS5/SQL2K, which is why I think there's a setting wrong here at home.

OH-- and the other odd thing is that when I set IE to 'prompt' me for first and third party cookies, I am not prompted-- is the type of cookie I'm setting different than most?? TIA
 

SantosLHalper

Ars Scholae Palatinae
1,347
This is a pretty simple issue, is the query returning data or not?

Paste this code above the part where you set cookies:
Response.Write = "Full Name: " & objRS("FullName")
Response.Write = "Sec Level: " & objRS("SecurityLevel")
Response.End

If data comes out, then it is not your database. If the values are empty, look at your query. Try running it in QA and see if it works. It could be a permission type error.

Do you have error handling turned on? This might prevent an error from displaying. Always turn OERN off during development.

If data is coming out and the cookie is simply losing its value when you go to the next page, then you have a cookie problem. Try turning your privacy settings down temporarily and see if that helps.

Also is it possible that IE is interpreting the new page as being on a different domain and thus rejecting the cookie. Try being more specific in your URL.

Also, I'm pretty sure that if you want the cookie to persist longer than the session, you will have to specify an expiration date. That would probably explain why you never see it in the cookies folder. Session cookies are not IFAIK saved to disk.

General programming notes, feel free to ignore.

1. Tab your code. Even if you are going through a "no-tabbing" phase, forget it and tab anyway. Other programmers will resent you less when they have to maintain your code.

2. If you are going to use Hungarian Notation, you should use it correctly. The data returned from a Request.Form is a string, not an object: Dim strUserName, strPassword

3. Remember to close and destroy your objects when you are done with them. CLDE (create-late-destroy-early). It is a good habit to get into. Some languages won't clean up after you.

4. Are you really sure you want to store the security level in a cookie. That seems intensely insecure. But I don't know your app. It seems though like anyone could "promote" themselves.

5. Tab your code. Truse me. Other programmers will curse you if you don't.
 

StanGable

Ars Legatus Legionis
18,817
I was tired when I replied above, so I apologize if I wasn't clear...

The query and cookies seem to be being set properly, because if I take the commmenting off of the

Response.Write Request.Cookies("MatUser")
Response.Write Request.Cookies("MatSecurity")

it will print the proper information (my name and my security level) at the top when it is submits the form to itself.

IMPORTANT------>BUT, after being redirected the cookie info disappears.

My privacy settings are set to "Accept all cookies", but set to medium at work where this problem doesn't exist.

Not specifying an expiration was not an accident- I only want their session to last as long as their browser is open for now (and I will actually have it time out sooner with inactivity in the near future).

The code is tabbed properly when viewed in the editor- I guess it just didn't copy/paste well into Ars.

Thanks for the other pointers. The security level is only meant to identify what that user is supposed to see- I have been using NT security for the the more secure stuff.

How would one go about 'promoting' themselves, as you say? I am curious?

BIG QUESTION, THEN: Why is the cookie data being lost after a redirect? Thanks for all the help! -rodbac
 

StanGable

Ars Legatus Legionis
18,817
Also- and this is related to my other post in this forum:

Would the fact that I am being forced to use NT authentication (because of having to use 'trusted_connection=yes') have anything to do with it?

My limited experience tells me no, but I am not surprised by anything with IIS and SQL Server anymore...

Thanks for any help you can offer... -rodbac
 
Status
Not open for further replies.