View Full Version : Session Cookies

12-11-2006, 05:05 PM
I'm new to using session cookies and need just a bit of help. On the introduction page to my project, I'm setting:

<%@ Language=VBScript %>



Then, on subsequent pages, I'm checking for the cookie, and redirecting if it's not there:

<%@ Language=VBScript %>

If NOT request.cookies("user") = "authenticated" Then
response.redirect "http://somepage"
End If


What I need to do is incorporate an ignore element (by user-agent or IP) into where it checks for the cookie. For instance, if a user has an IP of, it ignores whether they have the cookie or not and lets them view the page.

The reason I'm doing this is I have a search engine that's crawling the site and it doesn't always go through the front page - therefore, it's getting redirected on most of the pages it sees. So what I'd like to do is have the script see that user-agent or IP, then ignore the cookie requirement.

Is that possible?

12-12-2006, 02:36 PM
Anyone? :(

12-12-2006, 02:46 PM
I don't know if it's possible in regular ASP. I assume it is. I just don't know how. But in .net to get the IP address:

Dim TheIPAddress As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)

Dim IPaddress As String = (TheIPAddress.AddressList.GetValue(0).ToString)

Then you would just have to check IPaddress. If it is a good one then you would authenticate them through code.

I hope this helps.

12-12-2006, 02:56 PM
Not sure I understand completely, but you can check out the http_referer:

Let us know how it works out
Good luck;

12-12-2006, 03:04 PM
Thanks for that link. So I need to: Request.ServerVariables (HTTP_USER_AGENT). Then I need to take that result and compare it with the user-agent I'm expecting (the search crawler). If they match, ignore the redirect and cookie requirement and let the user view the page. If they don't match, follow the routine as normal and redirect if the cookie isn't present. How would I write that?

12-12-2006, 04:27 PM
Write it just as your other if statement when you redirect, cept this time use the user agent or whatever you are comparing with.

I think you can get it, if not let us know :)