寻找previous页面网址 [英] Finding previous page Url
问题描述
我试图找到previous page.Such,如果用户使用从网页A导航网页B Server.Redirect(B.aspx)$ C的网址$ C>,B页面可以显示的网址引用它。
i am trying to find the url of previous page.Such as if a user navigates from Page A to Page B using Server.Redirect("B.aspx")
, page B can display the url referring to it.
我已经尝试使用
Response.Write(Page.PreviousPage.ToString());
Response.Write(Request.UrlReferrer.ToString());
Response.Write(Context.Request.UrlReferrer.ToString());
Response.Write(Request.ServerVariables["HTTP_REFERER"].ToString);
但一切都是徒劳它给了我空例外
错误
推荐答案
如果它只是对于这种情况(你编程重定向到B.aspx),那么为什么不把查询字符串话要说,其中重定向是从哪里来的。这将是更可能跨越muliple浏览器类型和设备的工作
If it's only for this scenario (where you programatically redirect to B.aspx) then why not put something on the querystring to say where the redirect came from. This would be more likely to work across muliple browser types and devices.
一个优点这种方法是,你可以告诉和直接链接重定向之间的差异B.aspx(通过在您的网页之一,或输入URL到用户的链接地址基地)页面B.aspx。
One advantage to this approach is that you'll be able to tell the difference between a redirect to B.aspx and a direct link (either via a link on one of your pages, or from the user entering the URL into the address base) to page B.aspx.
引荐是后话了客户端提供的HTTP请求的一部分。因此,你不能依赖它。
The referrer is something the the client provides as part of the HTTP request. As such, you can't rely on it.
顺便说一句,这个问题是相关的:
<一href=\"http://stackoverflow.com/questions/149130/request-urlreferrer-null\">http://stackoverflow.com/questions/149130/request-urlreferrer-null
By the way, this question is related: http://stackoverflow.com/questions/149130/request-urlreferrer-null
更新
鉴于您的意见目前还不清楚这是不是编辑的所有文件等简单的解决方案。我怀疑,全球查找/替换可能是你最好的选择。
Update Given your comments it's not clear that's an easy solution other than "edit all your files". I suspect that global search/replace might be your best bet.
一些更多的背景:如果您使用Fiddler(或任何其他HTTP调试工具),你应该能够看到,当你执行重定向网址标头不被填充。例如,这是一个重定向的结果(即一个HTTP 302响应造成IE浏览器重定向到另一个页面):
Some more background: If you use Fiddler (or any other http debugging tool) you should be able to see that the Referrer header isn't being populated when you perform a redirect. For example, this is the result of a redirect (i.e. an HTTP 302 response causing IE to redirect to another page):
GET /webapplication1/WebForm3.aspx HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Accept-Language: en-GB
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; MS-RTC LM 8; Zune 3.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: (removed)
下面是通过点击StackOverflow.com的问题链接生成的HTTP请求:
Here is the HTTP request that is generated by clicking the "Questions" link on StackOverflow.com:
GET /questions HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Referer: http://stackoverflow.com/questions/772780/finding-previous-page-url
Accept-Language: en-GB
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; MS-RTC LM 8; Zune 3.0)
Accept-Encoding: gzip, deflate
Host: stackoverflow.com
Connection: Keep-Alive
您可以看到后,通过页面上的链接生成,生成Referer标头。
You can see that the later, generated by a link on a page, generates the Referer header.
这篇关于寻找previous页面网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!