having safe QueryStrings hyperlinks

Discussion in 'ASP .Net' started by Pat, Sep 2, 2005.

  1. Pat

    Pat Guest

    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
    Pat, Sep 2, 2005
    #1
    1. Advertising

  2. 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

    "Pat" wrote:

    > 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
    >
    >
    >
    =?Utf-8?B?R2FyeSBL?=, Sep 2, 2005
    #2
    1. Advertising

  3. Pat

    Pat Guest

    Can you provide samples please

    "Gary K" <> wrote in message
    news:...
    > 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
    >
    > "Pat" wrote:
    >
    > > 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
    > >
    > >
    > >
    Pat, Sep 2, 2005
    #3
  4. 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

    "Pat" wrote:

    > Can you provide samples please
    >
    > "Gary K" <> wrote in message
    > news:...
    > > 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
    > >
    > > "Pat" wrote:
    > >
    > > > 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
    > > >
    > > >
    > > >

    >
    >
    >
    =?Utf-8?B?R2FyeSBL?=, Sep 2, 2005
    #4
  5. 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


    *** Sent via Developersdex http://www.developersdex.com ***
    naijacoder naijacoder, Sep 2, 2005
    #5
  6. 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. :)

    "naijacoder naijacoder" wrote:

    > 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
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >
    =?Utf-8?B?R2FyeSBL?=, Sep 4, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ALPO
    Replies:
    1
    Views:
    353
    Steve C. Orr [MVP, MCSD]
    Nov 15, 2003
  2. Rob Meade

    Securing/Encrypting QueryStrings

    Rob Meade, Jan 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    Rob Meade
    Jan 22, 2004
  3. Anthony

    URL rewriting and querystrings

    Anthony, Oct 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    415
    Scott Allen
    Oct 26, 2004
  4. =?Utf-8?B?Sm9obiBIb3BwZXI=?=

    streams and querystrings

    =?Utf-8?B?Sm9obiBIb3BwZXI=?=, Jan 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    410
    =?Utf-8?B?Sm9obiBIb3BwZXI=?=
    Jan 21, 2005
  5. naija naija

    TreevIew having hyperlinks in the submenu

    naija naija, Sep 8, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    138
    naija naija
    Sep 8, 2004
Loading...

Share This Page