I need to find out from which page the request is coming from. For instance I have a button in page A and when clicked it redirects as follows
http://...../ClientName/names.aspx?nameId=4,
Page A's
URL = "http://...../Maintenance/names.aspx?nameId=4"
In page B, I want to be able to determine if it's coming from Page A. Notice that Page A and Page B have the same ending but in different folders... How ca开发者_StackOverflow社区n I know in page B if it's coming from the names.aspx in folder Maintenance?
Thank you
One hint: The URL Referrer is sent by the Browser (Request header). But this is not reliable, since (for instance) security tools might remove it from the request, as do some Proxies. I have used the same concept years back, but later failed because of this reason.
Example: http://darklaunch.com/2011/05/07/chrome-disable-referer-headers
On the other hand, if you can rely on the referrer - e.g. because you are in an Intranet, go ahead - as FT / Kuru said use HttpContext.Current.Request.UrlReferrer
. Very easy to use.
We have later solved this on application level:
- Give different HTML forms different logical names
- You can use hidden form fields to have extra information in the form
string myFileName = string.Empty;
System.IO.FileInfo PageFileInfo = new System.IO.FileInfo(Request.UrlReferrer);
myFileName = PageFileInfo.Name;
return myFileName;
BTW -- this might not be the best method for security, etc., as UrlReferrers can be spoofed pretty easily.
You can use HttpContext.Current.Request.UrlReferrer
to determine the referrer. Then you'll have to use RegEx to determine if it is the page you want (depending on how your app works) or String.SubString() to determine it.
精彩评论