473,399 Members | 3,888 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,399 software developers and data experts.

HttpHandler + Server.Execute to achieve URL Rewrite

I need to perform url rewriting to convert this (for example):
/blogs/feeds/popular/posts/

to this:
/blogs/feeds.aspx?type=popular&type2=posts

What I did was the following:

1. Created an http handler that parses the url and based on it will execute
another aspx page using Server.Execute

2. In the IIS I added ".*" to the ISAPI handler to be handled by .net

3. In web.config I added this so that it handles all urls coming in:

<httpHandlers>
<add verb="*" path="*/" type="MyHandler.FeedsHandler, FeedsHandler" />
</httpHandlers>

My question is: Is this a proper practice or are there any down sides to
using "server.execute" and "Setting the ISAPI handler to handle .* as .net
pages"?

Following is my handler code:

using System;
using System.Web;
using System.Configuration;

namespace MyHandler
{
/// <summary>
/// Summary description for FeedsHandler.
/// </summary>
public class FeedsHandler : IHttpHandler
{
#region Implementation of IHttpHandler
public void ProcessRequest(System.Web.HttpContext context)
{

HttpResponse objResponse = context.Response;
string myPath = context.Request.Path;

if (myPath.Contains("/feeds/"))
{
string[] mySplitPath = myPath.Split('/');

string myType2 = mySplitPath[mySplitPath.Length - 2];
string myType = mySplitPath[mySplitPath.Length - 3];

HttpContext.Current.Server.Execute("/feeds/feeds.aspx" +
"?type=" + myType + "&type2=" + myType2);
}
else
{
HttpContext.Current.Server.Execute(myPath + "Default.aspx");
}

}
public bool IsReusable
{
get
{
return false;
}
}
#endregion
}
}

Apr 20 '06 #1
3 6284
Hi Jeeran,

Thank you for posting.

As for the ASP.NET Httphandler, it perform processing on the coming
request according to the certain document extension configured in
web.config. Howerver, I don't think it can be mapped to process pure
directory path like "http://server/app/subdir/", such directory path can
only be intercepted by raw IIS isapi extension.

Also, for ASP.NET Url Rewriting, I think you can also consider use
HttpModule, since it runs before httphandler in the ASP.NET's server-side
http pipeline. here is an MSDN article describing this:

#URL Rewriting in ASP.NET
http://msdn.microsoft.com/library/en...ng.asp?frame=t
rue

====================
My question is: Is this a proper practice or are there any down sides to
using "server.execute" and "Setting the ISAPI handler to handle .* as .net
pages"?
==================

IMO, I don't think it's good idea to pass all requests to ASP.NET runtime
(through the aspnet_isapi.dll extension), especially for those static
documents (like image, script file ....). Because for static files, IIS is
the best one to process them and have better performance than the ASP.NET's
static file handler.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Apr 21 '06 #2
Thank you Steven.

I ended up using an isapi extension as you suggested (I used isapi_rewrite
from HeliconTech), but I did not use the isapi extension to handle every
url scenario, instead used isapi_rewrite to map the directory path to a .net
url which is then further parsed by an http handler -using the one in the
article you mentioned- and rewritten in its final shape.

My question now is; Is there any down-side to this architecture? Should we
only use either ISAPI or http handler?

As an example of what I did is the following:
1- The ISAPI rewrites this url (site.com//feeds/LANG/ITEMS/TYPE/) to (site.com/feeds/LANG/ITEMS/TYPE.aspx)
2- Then an http handler rewrites (site.com/feeds/LANG/ITEMS/TYPE.aspx) to
(site.com/feeds/feed.aspx?lang=LANG&items=ITEMS&type=TYPE)

Both using regular expressions which extract LANG and TYPE and makes it easy
to achieve all of this using just two rewrite rules, one in isapi_rewrite
and one in the http handler.

I figured this is a more flexible solution which allows:
1- Reducing the number of rules the ISAPI has to check for thus reducing
load on IIS.
2- Offloading most of the handling to the http handler will give developers
better access to further development and testing of new rules. Rather than
have to change the rules in the ISAPI filter each time.

Thank you.

Hi Jeeran,

Thank you for posting.

As for the ASP.NET Httphandler, it perform processing on the coming
request according to the certain document extension configured in
web.config. Howerver, I don't think it can be mapped to process pure
directory path like "http://server/app/subdir/", such directory path
can only be intercepted by raw IIS isapi extension.

Also, for ASP.NET Url Rewriting, I think you can also consider use
HttpModule, since it runs before httphandler in the ASP.NET's
server-side http pipeline. here is an MSDN article describing this:

#URL Rewriting in ASP.NET
http://msdn.microsoft.com/library/en...ewriting.asp?f
rame=t rue

====================
My question is: Is this a proper practice or are there any down sides
to
using "server.execute" and "Setting the ISAPI handler to handle .* as
.net
pages"?
==================
IMO, I don't think it's good idea to pass all requests to ASP.NET
runtime (through the aspnet_isapi.dll extension), especially for those
static documents (like image, script file ....). Because for static
files, IIS is the best one to process them and have better performance
than the ASP.NET's static file handler.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 5 '06 #3
Thank you for your followup Jeeran,

I think your currect implementation is good. And I just have one comment
about the URL rewriting in ASP.NET side, you're currently using httphandler
to do the redirecting. IMO, httpModule will be better since in the ASP.NET
runtime pipeline, httpmodule come at the earilier time to process comming
requests, so if we do the URL rewriting in httpmodule, that'll avoid the
request to pass other additional modules or processing. Here is a good
article on the ASP.NET runtime architecture which have described the
pipeline structure:

http://www.west-wind.com/presentatio...spnetworks.asp

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
May 8 '06 #4

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

Similar topics

6
by: PiGei | last post by:
hi all, I'm trying to use server.execute statement to include in an asp page another asp page with a parameter. That's because I've a parametric query in the second asp page and I have to pass...
3
by: Chris | last post by:
I have yet to understand or get a response on the issue I'm having. I'm taking an asp web application and migrating it from Windows 2K to 2003. I have the new website location (2003) settings...
1
by: sathya | last post by:
hi, i have problem in httphandler, my problem is that when i am trying to use server.execute(/default.aspx) i am getting error.... Here i am trying to redirect from home.aspx to...
2
by: Dune | last post by:
I'm trying to execute an aspx page by calling Server.Execute. The aspx page I'm trying to execute is in a different web app from the aspx page containing the Server.Execute statement. A slightly...
2
by: Chuck Haeberle | last post by:
We have a page which sends a copy of itself via email to customers. To enable this, the page calls Server.Execute on itself into a text stream and strips its own output down to HTML presentable to...
1
by: sathya | last post by:
hi, i have problem in httphandler, my problem is that when i am trying to use server.execute(/default.aspx) i am getting error.... Here i am trying to redirect from home.aspx to...
6
by: Sam | last post by:
My problem is that when I am trying to use Server.Execute("Somehandler.ashx") I am getting HttpException. System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer,...
2
by: Sike | last post by:
Hi everyone, I've been browsing this and a few other related newsgroups trying to get my head around this problem, and so far all the trails seem to go cold, without an acceptable solution being...
9
by: RN1 | last post by:
When a server encounters the line Response.Redirect("abcd.asp") in a ASP script, the server tells the browser that it has to be redirected to another page (which is abcd.asp, in this case)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.