What page sent me to the page being displayed

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

I'd like to know the page that sent me to the page being displayed.

I suppose I could update a session variable in each page, after I use the
value from the previous page, but that seems crude.

Isn't there a more elegant way?


Thanks
 
It says it is an optional field.
Do most browsers send it?
More importantly to me, can I test to see if it's present.
I'm asking because I won't be able to check out any code I might think would
work since my machine does not strip it.

Thanks
 
Mark Rae said:
[top-posting corrected]
It says it is an optional field.

That's right.
Do most browsers send it?

No browsers send it - it's a server variable...
More importantly to me, can I test to see if it's present.

if (Request.ServerVariables["HTTP_REFERER"] != nothing)
{

}


What language is your above code?


I made it vb, added it in my Page_Load and got
HTTP_REFERER IS NOTHING.

Do you know what might be the reason my IIS not returning it?

I wasn't sure if the = sign should be "is" so I tried both with the same
result.

If Request.ServerVariables("HTTP_REFERER") = Nothing Then
Response.Write("*** HTTP_REFERER IS NOTHING</br>")

Else

Response.Write("*** HTTP_REFERER IS NOT NOTHING</br>")

End If
 
Mark Rae said:
if (Request.ServerVariables["HTTP_REFERER"] != nothing)
{

}

What language is your above code?

C#

I thought C# used null rather than nothing

....snip
How did you open the page? A page will only have a referer if it was
opened from a hyperlink...

I been playing and find that if I open the page by inserting the URL (for
Default.aspx) into IE I got "nothing"

but as I move from page to page in my pages it is "not nothing"



In my .master I've put
b>You came from URL:</b>

<% Response.Write(Request.ServerVariables("HTTP_REFERER"))%>

And it's printout agrees with what I wrote in the first section

Looks like maybe for security IIS lets me see only my own URL.





I made an index.htm containing only:

<script type="text/javascript">

window.location.href = "Default.aspx"

</script>

This produced "nothing"

Changed to

<a href="Default.aspx">Click here</a>

This produced "not nothing"

All of which agrees with your statement about opening with a hyperlink.

Except when I use IE to open Default.aspx I do not get a referer. I don't
understand that one.



Thanks for the help
 
Mark Rae said:
Yes, that's correct.


That is also correct.


Yes, it would.


As expected.


So what's the problem...?


Typing a URL into a browser is not the same as opening a page by clicking
on a hyperlink, and will not generate a referer...


Well I guess we've covered it completely - thanks
 
Mark Rae said:
Yes, that's correct.


That is also correct.


Yes, it would.


As expected.


So what's the problem...?


Typing a URL into a browser is not the same as opening a page by clicking
on a hyperlink, and will not generate a referer...



This is what I'm doing. Can I prevent the write when the referer is blank??
<b>You came from URL:</b>

<% Response.Write(Request.ServerVariables("HTTP_REFERER"))%>

<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">

Go back</a>
 
Mark Rae said:
This is what I'm doing. Can I prevent the write when the referer is
blank??
<b>You came from URL:</b>

<% Response.Write(Request.ServerVariables("HTTP_REFERER"))%>

<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">

Go back</a>


Fairly simple in code using an <asp:Literal /> webcontrol.

<asp:Literal ID="litReferer" Runat="server" />

private void Page_Load(object sender, System.EventArgs e)
{
if (Request.ServerVariables["HTTP_REFERER"] != null)
{
litReferer.Text = "You came from " +
Request.ServerVariables["HTTP_REFERER"].ToString();
// etc
}
}


Fairly simple for you!
Thanks
 
Back
Top