having safe QueryStrings hyperlinks

P

Pat

I have a link i.e http://puppy/ShowBlank.aspx?b_id=34
When a user click on the link above and gets to it its fine..
But i want to prevent the user from copying the link and pasting the link to
a new browser window
If they do that i want to return an error for example "you can't come to
this page through this link"
Any ideas
 
G

Guest

Greetings & Salutations,

Try checking the Request.UrlReferrer property. If it does not correspond
with the page it's supposed to come from (and you could use an array of links
to check) then just reject the request (with appropriate error page message).

If the user cuts/pastes the link into a new browser window the referrer is a
blank string (I think, could be null).

Gary K
 
P

Pat

Can you provide samples please

Gary K said:
Greetings & Salutations,

Try checking the Request.UrlReferrer property. If it does not correspond
with the page it's supposed to come from (and you could use an array of links
to check) then just reject the request (with appropriate error page message).

If the user cuts/pastes the link into a new browser window the referrer is a
blank string (I think, could be null).

Gary K
 
G

Guest

I find it astonishing that you are a supposed programmer and you need samples
to access a class property, especially when there is plenty of free
documentation (c/ MSDN, TechNet, and that's just the official ones). You're
just lucky I'm in a generous mood today, Your Laziness.

The "UrlReferrer" property of the "HttpRequest" class (accessible through
"Page.Request") is itself a class ("Uri" class to be precise). This class
provides several properties to find out the various parts of the URL.

One thing to remember is that when there is no referrer, this property is
null/nothing.

Ooops, my generous mood is running out, so I'll just give you a couple
quickies.

if (Request.UrlReferrer==null) { /* no referrer */ }
if (Request.UrlReferrer.Host=="mydomain.com") { /* a page on my domain sent
this request */ }
if (Request.UrlReferrer.Host=="127.0.0.1") { /* the request came from this
ip address */ }

And since domains can come as either host/ip names then better check for
both (although if your site uses full urls for links you can get away with
just the host name check).

I'll leave it up to you to do further research on the other properties of
the "Uri" class.

Gary K
 
N

naijacoder naijacoder

Very well thanks for your generosity.
I taught you had something you could just post to help.
I was lazy and i agree only becos it was something i had to do with
limited time which i did using another solution.
Thx
 
G

Guest

It's alright, I do apologise for the way I expressed my sentiments. It was a
bad day, I was getting similar request from my users, I really hate lazy
thinking, and it was much easier to slag off at a faceless post rather than
the boss. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top