sk123
June 6th, 2006, 01:53 PM
*Note: Moved from C# forum
With C# 2005 we are sending notification emails to customers with the URL encoded. I want the user to be able to click on the email and be redirected to the correct page, after it is looked up in the database.
Example URL in email:
http://thissite.com/abc/12345
Example full URL:
http://thissite.com/FullURL.aspx?id=8566221144
After parsing the URL, you will look up the '12345' code in the database to get the actual URL you will be redirected to.
In the web.config, I have the following:
<httpHandlers>
<add verb="*" path="*/abc/*" type="RedirectHandler.Processor, RedirectHandler" />
</httpHandlers>
I have created an assembly to parse the URL (RedirectHandler), and redirect to the correct page, or if fails, redirect to the default set in the web.config.
public void ProcessRequest(HttpContext context)
{
try
{
//SETUP VARIABLES HERE>>>>>>>>>>>>>>>>
//Cut out for topic length
//Rewrite URL
if (targetURL.AbsoluteUri != "")
{
context.RewritePath(targetURL.PathAndQuery);
IHttpHandler handler = PageParser.GetCompiledPageInstance(targetURL.LocalPath, null, context);
handler.ProcessRequest(context);
}
}
} catch(Exception ex){
Uri redirect = new Uri(ConfigurationManager.AppSettings["DefaultRedirect"]);
context.RewritePath(redirect.PathAndQuery);
IHttpHandler handler = PageParser.GetCompiledPageInstance(redirect.PathAndQuery, null, context);
handler.ProcessRequest(context);
}
}
It works inside the application if I use Response.Redirect, but doesnt work if I click on the link from the email. What am I missing?
Thank You
With C# 2005 we are sending notification emails to customers with the URL encoded. I want the user to be able to click on the email and be redirected to the correct page, after it is looked up in the database.
Example URL in email:
http://thissite.com/abc/12345
Example full URL:
http://thissite.com/FullURL.aspx?id=8566221144
After parsing the URL, you will look up the '12345' code in the database to get the actual URL you will be redirected to.
In the web.config, I have the following:
<httpHandlers>
<add verb="*" path="*/abc/*" type="RedirectHandler.Processor, RedirectHandler" />
</httpHandlers>
I have created an assembly to parse the URL (RedirectHandler), and redirect to the correct page, or if fails, redirect to the default set in the web.config.
public void ProcessRequest(HttpContext context)
{
try
{
//SETUP VARIABLES HERE>>>>>>>>>>>>>>>>
//Cut out for topic length
//Rewrite URL
if (targetURL.AbsoluteUri != "")
{
context.RewritePath(targetURL.PathAndQuery);
IHttpHandler handler = PageParser.GetCompiledPageInstance(targetURL.LocalPath, null, context);
handler.ProcessRequest(context);
}
}
} catch(Exception ex){
Uri redirect = new Uri(ConfigurationManager.AppSettings["DefaultRedirect"]);
context.RewritePath(redirect.PathAndQuery);
IHttpHandler handler = PageParser.GetCompiledPageInstance(redirect.PathAndQuery, null, context);
handler.ProcessRequest(context);
}
}
It works inside the application if I use Response.Redirect, but doesnt work if I click on the link from the email. What am I missing?
Thank You