473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

RewritePath

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

Nov 9 '06 #1
1 4002
Don't worry about writing this yourself, you can find some great free code
to handle this, and more. I've use the UrlRewriting module from
http://www.urlrewriting.net/en/Default.aspx on a bunch of applications.
What's nice is you can even through regular expression matching into it.

In ASP.Net 2.0 though, some of this is built right in. You can already map
the faq.aspx page to something like your displaypage.aspx?id=1 with just a
section of the config file. Search for info on the new urlMappings section
of the web.config.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Massimo Necchi" <Ma***********@discussions.microsoft.comwrote in message
news:97**********************************@microsof t.com...
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

Nov 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt Howeson | last post by:
Some time ago I posted a request for help with a problem I was having sometime ago whereby a 404 error would result if any access to the Querystring had been made before the Context.Rewritepath is...
5
by: Guadala Harry | last post by:
I'd really appreciate it if someone would give me a"plain English" explanation of HttpContext.RewritePath(). I read the MSDN documentation, but still don't understand it. According to MSDN:...
2
by: Corey O'Mara | last post by:
Hello all, I'd like to have personalized URL's in my application. For example, http://mydomain.com/sites/page.aspx should be accessible via http://mydomain.com/sites/username/page.aspx. I'd like...
8
by: Jiho Han | last post by:
Can someone explain in layman's term, what HttpContext.RewritePath does? SDK doc explanation is kind of scant. Does it only affect the request processing for the duration of the processing(meaning...
1
by: Oytun YILMAZ | last post by:
Hi I thing I have found a critical bug about ASP.NET ReWritePath Function Here are the steps to reproduce: I have a solution with this items: "MasterPageWithoutUserControl.aspx"...
15
by: James Higgs | last post by:
For a long time, our product has had a "vanity URLs" feature where nice URLs are mapped to ASPX files in an IHttpModule implementation, using HttpContext.RewritePath(). This has worked beautifully...
3
by: asanford | last post by:
I want to create an ASP.NET web application that receives a form POST message, inspects the data, and reroutes the request to one of many different servers. I wrote an IHttpModule which...
0
by: cpnet | last post by:
I was playing around with Beta 2 of VS2005, .NET 2.0, and built an IHttpModule do allow me to have nice URL's in my web app. It was working great. I had a URL like: ...
0
by: Massimo Necchi | last post by:
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...
1
by: Keef | last post by:
Hiya... just wondering if anyone else has come across this problem, and if there is a solution... i'm writing a reasonably simple IHttpModule to rewrite URLs ... in the BeginRequest event i...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.