473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is URLRewriting what I want?

I'm building a site template that, hopefully, will be just one single ASPX
page.

There are 10 main districts (each getting a variation of the template), and
I could easily pass that info via a querystring:

mysite.com/default.aspx?district=3

But I'd like to be able to have the URL define that:

mysite.com/district/3

I'm looking at URL rewriting and I'm not quite sure if it does what I think
I want it do to.

It looks like URL rewriting (such as ISAPIrewrite) can take the above url:
'mysite.com/district/3' and then rewrite it as the querystring:
'mysite.com/default.aspx?district=3' which my application could use.

I was wondering if there would be a method to simply have
'mysite.com/district/3' point at /default.aspx. That way I could parse the
URL directly to get the variable rather than having to grab another
querystring. Is that something URL rewriting can do?

I COULD just do the former, but I'm trying to reduce the amount of
persistent querystrings we need to maintain.

-Darrel

Nov 19 '05 #1
4 1040
Yes, you are looking in correct direction.

Here are steps.

1. Override Application_BeginRequest(Object sender, EventArgs e) in Global.asax
2. Save the current path request

HttpContext ctx = HttpContext.Current;

string sPath = ctx.Request.Path.ToLower();

ctx.Items["OriginalPath"] = sPath;

then parse it out the query path and do HttpContext.Current.RewritePath("~/Default.aspx", "distict=3", "" ); (see help for RewritePAth)

3. in default.aspx Page_Load rewrite it back to the path saved in Items["OriginalPath"]

PS: Pay attention to # 3 otherwise all forms will point to default.aspx and not to /district/3.

George.

"darrel" <no*****@hotmail.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
I'm building a site template that, hopefully, will be just one single ASPX
page.

There are 10 main districts (each getting a variation of the template), and
I could easily pass that info via a querystring:

mysite.com/default.aspx?district=3

But I'd like to be able to have the URL define that:

mysite.com/district/3

I'm looking at URL rewriting and I'm not quite sure if it does what I think
I want it do to.

It looks like URL rewriting (such as ISAPIrewrite) can take the above url:
'mysite.com/district/3' and then rewrite it as the querystring:
'mysite.com/default.aspx?district=3' which my application could use.

I was wondering if there would be a method to simply have
'mysite.com/district/3' point at /default.aspx. That way I could parse the
URL directly to get the variable rather than having to grab another
querystring. Is that something URL rewriting can do?

I COULD just do the former, but I'm trying to reduce the amount of
persistent querystrings we need to maintain.

-Darrel

Nov 19 '05 #2
Thanks, George. I'm actually using ISAPIrewrite...not .net natively. It
doesn't quite do what I though, but realized that rewriting it as a
querystring is actually easier anyways...both for rewriting and for grabbing
it.

-Darrel
Nov 19 '05 #3
KMA
Another way is to write a custom page to handle 404s. None of the URLs that
the user keys exist, therefore all processing goes to your 404.

One problem I see is if the URL doesn't have an ASP ending (aspx, for
example) then none of your handler will be invoked. IIS just won't know who
should handle the request. Unless you have access to IIS admin, of course.
If you use shared hosting then this probably isn't the case.

The advantage of doing through custom 404 is that you can mix "real" and
"fake" pages freely.

"darrel" <no*****@hotmail.com> wrote in message
news:#w**************@tk2msftngp13.phx.gbl...
I'm building a site template that, hopefully, will be just one single ASPX
page.

There are 10 main districts (each getting a variation of the template), and I could easily pass that info via a querystring:

mysite.com/default.aspx?district=3

But I'd like to be able to have the URL define that:

mysite.com/district/3

I'm looking at URL rewriting and I'm not quite sure if it does what I think I want it do to.

It looks like URL rewriting (such as ISAPIrewrite) can take the above url:
'mysite.com/district/3' and then rewrite it as the querystring:
'mysite.com/default.aspx?district=3' which my application could use.

I was wondering if there would be a method to simply have
'mysite.com/district/3' point at /default.aspx. That way I could parse the
URL directly to get the variable rather than having to grab another
querystring. Is that something URL rewriting can do?

I COULD just do the former, but I'm trying to reduce the amount of
persistent querystrings we need to maintain.

-Darrel

Nov 19 '05 #4
Another way is to write a custom page to handle 404s. None of the URLs that the user keys exist, therefore all processing goes to your 404.
We do that as well. In fact, that's what we were doing up until this point.
We figured URL Rewriting at the IIS level would be more efficient, though,
rather than having it process a page and then redirect each time.
One problem I see is if the URL doesn't have an ASP ending (aspx, for
example) then none of your handler will be invoked.


Yes, that was the other problem, and the main problem with doing
URLRewriting in .net natively. I've been holding off on using ISAPI rewrite,
but now that I've downloaded the free version and got it up and running in a
matter of minutes, I'm not sure why I didn't do this earlier (and also
wonder why MS hasn't bought them out and incorporated it into IIS natively
yet).

-Darrel
Nov 19 '05 #5

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

Similar topics

4
by: Jon Maz | last post by:
Hi All, I'm doing UrlRewriting based on the model in Scott Mitchell's article "URL Rewriting in ASP.NET"....
4
by: Jon Maz | last post by:
Hi All, I'm doing UrlRewriting based on the model in Scott Mitchell's article "URL Rewriting in ASP.NET"....
0
by: Jon Maz | last post by:
Hi All, I'm doing UrlRewriting based on the model in Scott Mitchell's article "URL Rewriting in ASP.NET"....
8
by: Jon Maz | last post by:
Hi All, I'm doing UrlRewriting based on the model in Scott Mitchell's article "URL Rewriting in ASP.NET"....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.