Find the referring URL and parse it - c#

Okay my problem is there are two websites with two different servers. What I'm trying to do is write some of the buttons for website 1, but on a page on my server (website 2).
So to do this the approach is
User clicks on button from website 1.
User is redirected to website 2.
I need to know what page they came from so I know what product they are looking at. Which will be done by getting the referrer URL.
I then need to parse the URL's productID's number.
example URL: website1.com/ProductDetails/?referrerPage=1&productID=#######&tab=Tile
I know that I need to use this piece of code to store the referrer URL in a string:
myReferrer = Request.UrlReferrer.ToString();
I don't really know where to place it tho. I'm guessing in my .cs file where my button is?
protected void btnEstimate_Click(object sender, EventArgs e)
{
connection strings
{
does stuff
{
does stuff
}
So my question is how do I get the referring URL, and then parse out the item ID?
Thanks for the help in advance. If anything is unclear please ask... this is my first time asking a question so I may be unclear. Thanks!

This should give you what you want:
Making Sense of ASP.NET Paths
Note that a fully qualified URL including querystring and extra path is a Uri instance rather than string. You can use the UriBuilder.Query Property to extract the query string parameter(s):
You need to parse the URI in the Page_Load method of the receiving site's page.
UriBuilder.Query Property

There's a server variable called HTTP_REFERER. You can access it with Request.ServerVariables("HTTP_REFERER")
It's misspelled, I know, but that's how you really need to call the server variable.
Your referrer server variable is only going to be populated if the user clicks on a link. AFAIK if you redirect, that variable is going to be empty.
Wikipedia Referer Article

Related

C# How can I mark a URL invalid/obsolete?

I have a URL something like below. The URL gets generated each time, basically links are ephemeral. I want to mark this link as obsolete/invalid once it has been accessed in a browser. The second time when we access this URL, it should say invalid link. URL format is having an auth token. How can we do this in C#?
http://example.com/ui/landing?authToken=wwlC7bjUugIT5lo8uuX8d2wQhS__k6l80fSwPKzFuJWwDANgGVQtNT6C3q1lGcNk1p_ApBdurzPTayOzaGb6YibAdTKfzBdhKCcTNZwO54mg1KU_lPD6Zmg
Link must be marked as invalid once used.
I don't think this can be done just by code.
I think a workaround would be to store the links on your server (database, file or watever). When someone uses the link you can check on that db if the link has been used and mark it as "used" if not.
Something like:
id
Link (string)
Used (boolean)
1
https://stack...
1
2
https://stack...
1
3
https://stack...
0

How to Open Default browser and target an element?

Hi all I have done some google work and not come up with a great deal apart from using the browser within a From which I dont want to do.
Has anybody some sample code or a good resource that is detailed enough to get me on my way plesae
So for example
Process.Start("https://www.google.com")
and target the search element with a string and click search.
Using the default browser
Please help me...
Doing something like this would work:
string mySearchQuery = "this is a search example";
Process.Start("https://www.google.com/search?q=" + Uri.EscapeDataString(mySearchQuery));
If I'm understanding you correctly, this would use the default browser set in windows, then the query is just passed in as a GET request (that's the ?q variable).

ABBYY OCR - How to use multiple region parameters in the Uri?

I'm working with ABBYY cloud OCR, when my popruse is to scan 3 specific places in each document that I'm scanning. These 3 places will always be the same so I want to use the ProcessFields function do it and having some problems with it.
When I want to scan only one specific place I used this :
string url1 = String.Format("http://cloud.ocrsdk.com/processFields?region=0,0,200,200&language=english");
When trying to scan 2 places I've tried this :
string url1 = String.Format("http://cloud.ocrsdk.com/processFields?region=0,0,200,200 region 100,100,100,100&language=english");
it gave me an error.
Anyone has any advise how to do it?
I also tried defieng 3 Uri's but as the upload is done only once - how can I reach the 2 other Uri's without scanning it again?
thanks a lot!
According to documentation of processField method, you can't pass field parameters in URI, you should form an XML and submit it using POST method instead of GET. There is also a sample XML file on that page.
Simple method with URI works only for one field and processTextField method.

Advice needed: Geolocation for c# web app - need country location to set what user can see or not

My scenario is I want to trap the user's country when they access the web page. Based on the user's country i want to set a cookie that will allow me to do a simple "if" statement in the code behind that would let them to see certain information on web pages.
I started doing some research and i can use the Google Geocode V3 and get the country from code behind c#. But to get the Google Geocode to work i need to pass in the longitude and latitude.
And the only way i've seen this is from Javascript call like:
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
});
}
So i'm hoping for some advice if I'm doing this right.
On the loaded method in my c# code I think I can get the javascript to run by ScriptManager.RegisterStartUpScript method. So my challenge now is getting the latitude and longitude values. Since i'm not going a button event or something, i need to get those values out and then pass them into my c# method that would get the country code using the Google Geocode.
Does that sound right? If this is the right path, can someone suggest how i could get those values from the javascript?
thanks.
You could make an Ajax call to your server which contains the client's geolocation.
What about using RegionInfo.CurrentRegion instead? That will give you the country according to the browser headers assuming you have globalization culture turned to auto. This is simpler, but will also not be 100% correct all the time since the user can change their culture settings.
You may also want to look into using IP address based geolocation which might be a little more accurate.
It would help to know why you're trying to do this.
Most sites that really need to make sure that content stays within national boundaries work with content that is chargeable - for instance, most music sites, Amazon, and so on.
Their simple, yet effective, technique is to use the country on the user's billing address on their credit card.

How to GET reCAPTCHA picture address?

This is my idea:
I get this address from source, for example: http://api.recaptcha.net/challenge?k=6Lc_Wb0SAAAAAPpDWSnsxg7rFxSJT46Wmic3Ximb
Then I get "challenge" from this site, for example: challenge : '03AHJ_VuumDpsD-dz-rSeL_Vyd5fUqHMJLNtlpiyaEq0RzDhsaNTWTydaOcYk5cdRX55C6VyaojWJwCa6T6PF8LF4Io5NUC09Kj0HRNczh9tJXBsrx26BcfBtrwvPabvbR_SnJXdmc9YS2L76PqI9EdtfXPhhCV9V2jw'
Then I get address of picture, for example: http://www.google.com/recaptcha/api/image?c=03AHJ_VuumDpsD-dz-rSeL_Vyd5fUqHMJLNtlpiyaEq0RzDhsaNTWTydaOcYk5cdRX55C6VyaojWJwCa6T6PF8LF4Io5NUC09Kj0HRNczh9tJXBsrx26BcfBtrwvPabvbR_SnJXdmc9YS2L76PqI9EdtfXPhhCV9V2jw
But there is a problem - pic is other than I have to write. Can you tell me how I can get oryginal address?
If the image you get doesn't match up with the one that you have to type then I'm guessing you aren't passing the same challenge code to the verification method of the api as to the image part.
It would help if you could paste a bit of code.
If you look at the non-javascript API call output for how it actually gets fetched without all the javascript getting in the way, there wouldn't appear to be a reason your strategy would give the wrong image.
http://www.google.com/recaptcha/api/noscript?k=6Lc_Wb0SAAAAAPpDWSnsxg7rFxSJT46Wmic3Ximb
Mike got the point you need to pass recaptcha_challenge_field=03AHJ_VuumDpsD-dz-rSeL_Vyd5fUqHMJLNtlpiyaEq0RzDhsaNTWTydaOcYk5cdRX55C6VyaojWJwCa6T6PF8LF4Io5NUC09Kj0HRNczh9tJXBsrx26BcfBtrwvPabvbR_SnJXdmc9YS2L76PqI9EdtfXPhhCV9V2jw

Categories

Resources