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,
Developer forum
E-mail notifications
Page redirection
José Silva
Posted on 27/07/2011 11:40:41
Replies
Imar Spaanjaars
Posted on 27/07/2011 14:32:19
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
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
Posted on 28/07/2011 11:39:04
Hi Imar,
thanks for your prompt response!
I tried with the following:
but I'm getting this exception:
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); } }
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll Can you advise plz?
Jeppe Eriksson Agger
Posted on 28/07/2011 11:45:01
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
Posted on 28/07/2011 12:02:36
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
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
Posted on 28/07/2011 12:45:33
Yes it is, thanks.
So... any ideas?
So... any ideas?
José Silva
Posted on 28/07/2011 13:44:11
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.
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
Posted on 28/07/2011 16:20:33
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
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