Hi everybody,
I'm developing a simple web site for a friend of mine and I need an help for
the folloeing situation: I am planning to map friendly page name (like
'/faq.aspx') to more complicated ones (like '/displaypage.aspx?id=1'). I've
done an internet search and I found that I can achieve this using httpModule.
My first attempt was to using RwritePath in the BeginRequest event handler,
retrieving the id associated to the friendly page and rewrite the path (using
RewritePath) with the "complicated" one. Everything worked fine.
Then I thought to optimize the site in order to reduce the number of
connection to the database which stores the link between friendly pages and
ids: to do this I thought to put the Dictionary containing the associations
into the Session object in order to avoid connecting to the db after the
first load.
To do this I moved all the code from the BeginRequest handler to the
PostAcquireRequestState one. Everything seems to work fine but the
RewritePath as no effect.
Here's the bit of code:
private void context_PostAcquireRequestState(object sender, System.EventArgs
e)
{
String RequestedUrl =
HttpContext.Current.Request.Path.ToLowerInvariant( );
if (System.IO.Path.GetExtension(RequestedUrl)==".aspx ")
{
String ButtonKey =
RequestedUrl.Substring(RequestedUrl.LastIndexOf("/") + 1);
if (HttpContext.Current.Session["MenubarButtonsList"] == null)
{
HttpContext.Current.Session["MenubarButtonsList"] =
UserComponent.GetMenubarButtonsList(HttpContext.Cu rrent);
}
MenubarButtonsList ButtonsList =
(MenubarButtonsList)HttpContext.Current.Session["MenubarButtonsList"];
if (ButtonsList.ContainsKey(ButtonKey))
{
MenubarButton ReqButton = ButtonsList[ButtonKey];
if (ReqButton.RewritePath)
{
System.Text.StringBuilder NewUrl = new
System.Text.StringBuilder(HttpContext.Current.Requ est.ApplicationPath);
NewUrl.Append("/PageDisplayer.aspx?id=");
NewUrl.Append(ReqButton.Id);
HttpContext.Current.RewritePath(NewUrl.ToString()) ;
}
}
}
}
Any idea??
Thanks.
Massimo Necchi