473,657 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Configur ation;

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

HttpResponse objResponse = context.Respons e;
string myPath = context.Request .Path;

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

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

HttpContext.Cur rent.Server.Exe cute("/feeds/feeds.aspx" +
"?type=" + myType + "&type2=" + myType2);
}
else
{
HttpContext.Cur rent.Server.Exe cute(myPath + "Default.aspx") ;
}

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

Apr 20 '06 #1
3 6300
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.dl l 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=ITEM S&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.dl l 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
5287
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 the value <% Server.Execute("result.asp?key=2") %> I can't do it. That's the error message I get:
3
6868
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 correct, i.e. enable parent paths, etc. and still get these errors: Server object error 'ASP 0228 : 80004005' Server.Execute Error /ASP_Procedures/PageHeader.asp, line 60 The call to Server.Execute failed while loading the page.
1
2798
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 default.aspx (both file isin sharepoint).I have give a copy of my code below..
2
3330
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 clearer explanation... Page1 exists in WebApp1. In the code-behind of Page2 in WebApp2, I have put Server.Execute("Path to Page1 in WebApp1"). When I call Server.Execute(String) using "http://localhost/WebApp1/Page1.aspx", everything works ok...
2
1963
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 the customer. In our Test environment (but not our DEV or Local envs) we are experience an ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot the server before any of our other ASP.NET apps will work. This is a...
1
2321
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 default.aspx (both file isin sharepoint).I have give a copy of my code below..
6
4739
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, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3179617 System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean...
2
2975
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 reached. I'm posting here because there seems to be a few MVP's knocking around, and if they dont know, then it's a safe bet nobody does. I'm beginning to think that what I want to do is simply not possible - but i'll put it out there once...
9
4340
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). The browser then makes a new request to the server to redirect itself to abcd.asp after which the user gets redirected to abcd.asp. But in case of Server.Execute (or Server.Transfer), when the server
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.