Developer forum

Forum » Development » Page redirection

Page redirection

José Silva
Reply
 Hi,

I need to have redirection to certain pages based on user's country (from IP address) and domain typed by user.
I have tried httphandlers but they are not being called.
What is a possible solution for this?

ps: I need to have Url Rewriting active.

Thanks, 

Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
Hi José,

You can handle redirects in the Application_AuthenticateRequest event in Global.asax.

And to make handlers work, you may need to bypass Dynamicweb's GlobalAsax.Application_OnPreRequestHandlerExecute. Something like this:

public void Application_OnPreRequestHandlerExecute(object sender, EventArgs e)
{
  if (! current request ends with .axd)
  {
    GlobalAsax.Application_OnPreRequestHandlerExecute(sender, e);
  }
}

Hope this helps,

Imar
 
José Silva
Reply
 Hi Imar,

thanks for your prompt response!

I tried with the following:

public void Application_OnPreRequestHandlerExecute(object sender, EventArgs e)
{
    if (!HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".axd"))
    {
      Application_OnPreRequestHandlerExecute(sender, e);
    }
}
but I'm getting this exception: 
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

Can you advise plz?
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi José

It seems to me, that you're creating an infinite loop for all extensions other than ".axd" by doing that. In essence you're saying: if extension is not axd then go back an check the extension again. This keeps on happening because the extension never changes.

Hope this helps.

- Jeppe

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
Yep, Jeppe is right. You shouldn't be calling Application_OnPreRequestHandlerExecute in the if (which is the current method) but GlobalAsax.Application_OnPreRequestHandlerExecute(sender, e); which calls into the Dynamicweb codebase.

The GlobalAsax variable is declared at the class level with this code:

Dynamicweb.Admin.Global GlobalAsax = new Dynamicweb.Admin.Global();

Hope this helps,

Imar
 
José Silva
Reply
Yes it is, thanks.

So... any ideas?


 
José Silva
Reply
 I now have this piece of code:

private static Dynamicweb.Admin.Global GlobalAsax = new Dynamicweb.Admin.Global();

public void Application_OnPreRequestHandlerExecute(object sender, EventArgs e)
{
if (!HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".axd"))
{
GlobalAsax.Application_OnPreRequestHandlerExecute(sender, e);
}
}

And this configuration:

<add verb="*" path="*.aspx" type="GeoIPCountry.GeoIPCountryHandler, GeoIPCountry" />

But it's not working yet.
I'm gessing it will be best to hand my logic within this method.


 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer
I thought you were using axd handler to do this, yet you map the ASPX extension to your custom IP checker. In that case, the exception for the axd handler won't help you.

For this situation, I don't know what to do. You need to hook up the Dynamicweb handler so you can't bypass the request for all ASPX files. Can you access the IP checker programmatically and do it yourself in Application_AuthenticateRequest? That's how I've done it a couple of times.

Cheers,

Imar
Votes for this answer: 0

 

You must be logged in to post in the forum