Results 1 to 8 of 8

Thread: [2008] Is there an event when navigating in ASP.NET?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    [2008] Is there an event when navigating in ASP.NET?

    Yeah I know my title may be a little oversimplified.

    What I want to know, is how can I detect when a user is naviating to a different page from my ASP.NET application, but them just clicking a standard anchor tag. There is no postback involved so I am not sure if there is actually a valid method without a bunch of weird client side JS wireup to the document unload or something.

    The goal is to rewrite HTTPS as HTTP when navigating from a sercure section of the site, to a non secure section. The issue is that there are relative links on the page, so if you are on an HTTPS page, and there is a href link to "../home.htm" it will resolve to HTTPS, which I want to prevent.

    Currently I had to change the hrefs all to fully qualified URLs, but that is not the best way to do it, so I want to know how I can do it with relative paths.

    I tired some of the events in the global.asax, but they didn't seem to fire off, likely because there is no postback and the ASP.NET runtime is not being invoked for these simple a href links.
    Last edited by kleinma; Jun 18th, 2008 at 12:24 PM. Reason: misspelling in title

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Is there an event when naviating in ASP.NET?

    You should look into creating an HTTP handler which will look at the URL that has been requested, the Referrer URL and using 'whatever logic' perform the 301 or 302 as required.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Is there an event when navigating in ASP.NET?

    I'll look into it, but I am not writing any more code unless this client pays me to do so

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Is there an event when navigating in ASP.NET?

    But it's quite simple. You only need to create a set of 'mappings' in your web.config (or somewhere else) to indicate whether your page is under https or http. When a request comes in, have your handler look at it, check the security level and redirect accordingly. Just a few lines...

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Is there an event when navigating in ASP.NET?

    does this also work when the navigation location will be outside the ASP.NET application?

    For example, the app is at

    https://www.somesite.com/aspnetapp/default.aspx

    On that page is a standard anchor tag that links to

    ../somepage.htm

    which will resolve to

    https://www.somesite.com/somepage.htm
    when I want it to be
    http://www.somesite.com/somepage.htm

    I just want to make sure it is not going to matter that where I am navigating to is not in the directory structure of the asp.net application.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Is there an event when navigating in ASP.NET?

    It won't work for that, unfortunately. You'll need to create a separate HTTP Handler for the root of the site, mapping .html extension to the ASP.NET ISAPI DLL so that the HTTP Handler can hook into the process pipeline.

    If this is too complicated, then there may be other equally obscure ways to do this. For example, you could run all of the .NavigateUrl assignments through a method before assigning them to hyperlinks, and letting the method resolve them to full URLs.

    Another way would be to use javascript to attach a method (onclick) to all the hyperlinks on a page and everytime one is clicked, have it call a web service to perform the URL resolution for you. Slow.

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Is there an event when navigating in ASP.NET?

    yet another method was to hard code the 15 links on the page to http.

    Makes my life a bit harder between the dev and production site, but its just the links in this one template file, I never need to click them on the dev box.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Is there an event when navigating in ASP.NET?

    Oh yeah, there's that too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width