jimbona27
asked on
Request.ServerVariables("HTTP_REFERER") get a keys value
hi there,
I need to get the value of a key within the Request.ServerVariables("H TTP_REFERE R") variable.
if I have a variable called test within the http_referer how can I get the value of the it out?
test.aspx?a=1&b=2&c=3&d=4& e=5&f=6
find e, retrieve value 5
I need to get the value of a key within the Request.ServerVariables("H
if I have a variable called test within the http_referer how can I get the value of the it out?
test.aspx?a=1&b=2&c=3&d=4&
find e, retrieve value 5
Request("e") will return value 5
ASKER
this works although I need to return the previous querystring value not the present one
if I have
test.aspx?a=1&b=2&c=3&d=4& e=5&f=6
then loads this, not the f value changing
test.aspx?a=1&b=2&c=3&d=4& e=5&f=10
i need to get the value f=6 out, hence using HTTP_REFERER.
using request("f") displays 10, rather than 6??
if I have
test.aspx?a=1&b=2&c=3&d=4&
then loads this, not the f value changing
test.aspx?a=1&b=2&c=3&d=4&
i need to get the value f=6 out, hence using HTTP_REFERER.
using request("f") displays 10, rather than 6??
To find key/values for a different path than the current executing page, you can create a custom HttpRequest object. The use the usual querystring etc.
string sFile = "test.aspx?a=1&b=2&c=3&d=4 &e=5&f=6";
string sQ = "";
int iQM = sFile.IndexOf("?");
if(iQM>0)
{
sQ = sFile.Substring(iQM+1);
sFile = sFile.Substring(0, iQM);
}
System.Web.HttpRequest hr = new HttpRequest(sFile, "http://localhost/", sQ);
Response.Write(hr.QueryStr ing["f"]);
string sFile = "test.aspx?a=1&b=2&c=3&d=4
string sQ = "";
int iQM = sFile.IndexOf("?");
if(iQM>0)
{
sQ = sFile.Substring(iQM+1);
sFile = sFile.Substring(0, iQM);
}
System.Web.HttpRequest hr = new HttpRequest(sFile, "http://localhost/", sQ);
Response.Write(hr.QueryStr
ok you have
test.aspx?a=1&b=2&c=3&d=4& e=5&f=6
you can store it in string
str="test.aspx?a=1&b=2&c=3 &d=4&e=5&f =6"
by using spilt first by ? , then by &
you can get array of a=1 , b=2 like this
test.aspx?a=1&b=2&c=3&d=4&
you can store it in string
str="test.aspx?a=1&b=2&c=3
by using spilt first by ? , then by &
you can get array of a=1 , b=2 like this
ASKER
Dim sFile As String = Request.ServerVariables("H
Dim sQ As String = ""
Dim iQM As Integer
Int(iQM = sFile.IndexOf("?"))
If iQM > 0 Then
sQ = sFile.Substring(iQM + 1)
sFile = sFile.Substring(0, iQM)
End If
following lines bum out - cannot be used as an expression
System.Web.HttpRequest(hr = New HttpRequest(sFile, "http://localhost/", sQ))
'Response.Write(hr.QuerySt
I used C# - not VB.Net. QueryString cannot handle the square brackets, make it like:
Response.Write(hr.QueryStr ing("f"))
Response.Write(hr.QueryStr
Dim hr as System.Web.HttpRequest = New HttpRequest(sFile, "http://localhost/", sQ)
Response.Write(hr.QueryStr ing("f"))
I don't like VB.Net :(
Response.Write(hr.QueryStr
I don't like VB.Net :(
ASKER
Dim qs As String = Request.ServerVariables("H
Dim bits() As String
Dim i As Integer
bits = Split(qs, "?")
bits = Split(bits(1), "&")
For i = 0 To UBound(bits)
Response.Write(bits(i) & "<BR>")
Next i
Response.Write(bits(1))
this works.
displays all the keys within the original querystring.
how can I get the value out of it for a given key?
ASKER
Dim qs As String = Request.ServerVariables("H TTP_
Dim bits() As String
Dim i As Integer
bits = Split(qs, "?")
bits = Split(bits(1), "&")
For i = 0 To UBound(bits)
Response.Write(i & " " & bits(i) & "<BR>")
Next i
bits(6) holds what I want but I cant take this for granted, how can I say request(5) within my bits array? or something to that affect?
Dim bits() As String
Dim i As Integer
bits = Split(qs, "?")
bits = Split(bits(1), "&")
For i = 0 To UBound(bits)
Response.Write(i & " " & bits(i) & "<BR>")
Next i
bits(6) holds what I want but I cant take this for granted, how can I say request(5) within my bits array? or something to that affect?
ASKER
sorry not request(5) but request(keyname)
any ideas?
many thanks
any ideas?
many thanks
Did you even look at my postings?
ASKER
oh sorry, just tried again with the vb.net change and it does not display anything?
Dim sFile As String = Request.ServerVariables("H TTP_REFERE R")
Dim sQ As String = ""
Dim iQM As Integer
Int(iQM = sFile.IndexOf("?"))
If iQM > 0 Then
sQ = sFile.Substring(iQM + 1)
sFile = sFile.Substring(0, iQM)
End If
Dim hr As System.Web.HttpRequest = New HttpRequest(sFile, "localaddress/", sQ)
Response.Write(hr.QueryStr ing("f"))
Dim sFile As String = Request.ServerVariables("H
Dim sQ As String = ""
Dim iQM As Integer
Int(iQM = sFile.IndexOf("?"))
If iQM > 0 Then
sQ = sFile.Substring(iQM + 1)
sFile = sFile.Substring(0, iQM)
End If
Dim hr As System.Web.HttpRequest = New HttpRequest(sFile, "localaddress/", sQ)
Response.Write(hr.QueryStr
ASKER
iQM = sFile.IndexOf("?"))
iQM is empty?
iQM is empty?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
this seems to work so many thanks. i'll just test a few things.
ASKER
does this change anything with the request.querystring variables? thanks.
This way you have created a new HttpWebRequest object - and can be used in conjunction with the normal Request object.