Click here to Skip to main content
16,018,818 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
Hi,

We have intranet(say abc.com), and a button on intranet to access a website(say xyz.com). I have to provide access to xyz.com, only if they com from intranet.
Intranet is in html where as the website is in C#.

I have written the following code in the intranet page (where the website link is present)
HTML
<form action="" method="post" name="form1" target="_blank">
<input name="culture" type="hidden" value="1">
<input name="auth" type="hidden" value="culture">
<input type="button" class="button" value="test page from link" onClick="location.href='http://xyz.com/'">
</form>


I have used Request.UrlReferrer.ToString(); in C# page to authorize the previous page they have come from. But its returning NULL.

Is there any other way to check the previous page url?


Thanks in advance,
Suma.
Posted
Updated 11-Mar-22 22:45pm
v2

string urlName = Request.UrlReferrer.ToString();


The situations where it doesn't work:

using Response.Redirect / Server.Transfer;
clicking on a Favorite, History, or the recently-typed URLs list;
clicking on 'Home' in IE's toolbar, or an item in IE's 'Links' toolbar;
using location.href or location.replace() in client-side JScript/JavaScript/VBScript;
using HierMenus (details);
typing the URL directly in the browser and hitting Enter or clicking 'Go';
launching a clickable URL from an e-mail or MS Office document;
using Response.AddHeader or <meta http-equiv=refresh> to redirect;
loading the URL with XML

in referer veriable u will get the previous page name.

Hope this can help you.
 
Share this answer
 
v2
hello there
on the following URL other ways to do that are given
http://www.dotnetcurry.com/ShowArticle.aspx?ID=89[^]

these methods may be helpful ............
Best regards
 
Share this answer
 
v2
There is no way to get the previous page Url. However, I think you can resolve this issue in two ways
1.IP white listing (White list the IP address of your intranet(abc.com) in xyz.com )
2.Pass a query string to the web site say "location.href='http://xyz.com?request_from=abc and validate your request.
 
Share this answer
 
you may also use this code I use this for my website
Request.ServerVariables["HTTP_REFERER"];
 
Share this answer
 
And, you are crossing borders. For safety, internal information should never go out to the internet to prevent information leakage about your internal network and services. So maybe it is no good practice to rely on internal urls getting passed to a webserver. e.g. read
http - Does a local html file send its file path as referrer? - Stack Overflow[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900