Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HttpHandler

2 views
Skip to first unread message

Joe

unread,
Apr 11, 2008, 3:10:14 PM4/11/08
to
Is it possible to return a page in the ProcessRequest method?
For example if someone enters www.mydomain.com/user/joe I want to return a
page user.aspx?user=joe but I don't want the URL to show in the browser. I
tried context.Server.Transfer but it always returns an error.
context.Request.Redirect works but then the URL changes.

Any ideas?

Thnaks,
Joe


George Ter-Saakov

unread,
Apr 11, 2008, 3:46:45 PM4/11/08
to
Google "rewrite url in ASP.NET"

George.

"Joe" <jbas...@noemail.noemail> wrote in message
news:exlL9fAn...@TK2MSFTNGP03.phx.gbl...

Steven Cheng [MSFT]

unread,
Apr 13, 2008, 10:40:07 PM4/13/08
to
Hi Joe,

As George has mentioend, what you want to do is called "Url Rewriting" in
web application.

In ASP.NET, you can use a custom httpmodule to perform such URL rewriting
task. For example, in the "Begin_Request" event, you can parse the original
url and redirect the request to the actual url/page. Here are some web
articles introduced some of these means:

#Tip/Trick: Url Rewriting with ASP.NET
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-wi
th-asp-net.aspx

#URL Rewriting in ASP.NET
http://msdn2.microsoft.com/en-us/library/ms972974.aspx

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Joe" <jbas...@noemail.noemail>
>Subject: HttpHandler
>Date: Fri, 11 Apr 2008 15:10:14 -0400

Steven Cheng [MSFT]

unread,
Apr 16, 2008, 6:49:39 AM4/16/08
to
hi Joe,

Have you got any progress on this or does the information in previous
mesages help you some?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

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

--------------------

David

unread,
Apr 16, 2008, 10:38:20 AM4/16/08
to
Hi,

I'm very new to ASP.NET. I have over 10 years of C++ experience in MFC
and Games programming etc, but web programming is something I have just
started.

Sorry for the rather silly question, but can someone explain what a
HTTPHandler is for?

I gather they can handle custom file extensions, but they seem to be
used to handle other events (such as authentification).

In my normal programming practise I would create a C++ class (or perhaps
in this case a C# class) to handle any logic, so what specifically would
a HTTPHandler or a HTTPModule do that a class couldn't?

Thanks

David

Mick Wilson

unread,
Apr 16, 2008, 10:52:56 AM4/16/08
to
> In my normal programming practise I would create a C++ class (or perhaps
> in this case a C# class) to handle any logic, so what specifically would
> a HTTPHandler or a HTTPModule do that a class couldn't?

An HTTPHandler is a class that implements the IHTTPHandler interface,
which is mainly the one method:

void ProcessRequest(
HttpContext context
)

An HTTPHandler gives you access to the request earlier in its
lifetime, which can be useful for simple tasks.

Scott Hanselman's article shows you a pretty quick example here:

http://www.hanselman.com/blog/CompositingTwoImagesIntoOneFromTheASPNETServerSide.aspx

One of the uses he found for HTTPHandlers was presenting an image of a
check to the user. No need for generating a control tree, events,
etc., so it made sense to handle it in a simpler way.

Hope this helps.

Alexey Smirnov

unread,
Apr 16, 2008, 11:02:22 AM4/16/08
to
On Apr 16, 4:38 pm, David <a...@asd.com> wrote:
> In my normal programming practise I would create a C++ class (or perhaps
> in this case a C# class) to handle any logic, so what specifically would
> a HTTPHandler or a HTTPModule do that a class couldn't?

HTTPHandler can be called directly from the browser by using its file
name in the URL. In C++ you can create an ISAPI that could do the same
job but cannot be called from the URL, you have to configure it in
IIS.

David

unread,
Apr 16, 2008, 11:24:27 AM4/16/08
to
Thanks Alexey,

I think I get what you are saying (Mick too in his post). One question
that remains is that some code or logic called be called in the
'Page_Load' method of an aspx page. So in the example that Mick gave,
the check image
(http://www.hanselman.com/blog/CompositingTwoImagesIntoOneFromTheASPNETServerSide.aspx)
I can't see why that couldn't be done in a C# class (called in the
'Page_Load' method for example)?

Is it that it is just easier in a HTTPHandler? Obviously it's there for
a good reason! Perhaps my inexperience in web programming is getting in
the way of understanding this.

Thanks,

David

George Ter-Saakov

unread,
Apr 16, 2008, 11:26:15 AM4/16/08
to
I had pretty much same question a while back... Here is my answer (to
myself).

You have 2 ways to process browser request...
1. Write ASPX page
2. Write HTTP Handler.

HTTP handler is low level and usually not used to produce HTML.
ASPX page is a high level and mostly used to generate HTML page.

As a matter of fact ASPX page processing is implemented using HTTP handler.
People from Microsoft wrote an HTTP handler to find aspx page, create
WebControls, run it... send output to browser...

There is nothing you can not do with HTTP handler that you can not do with
ASPX page.. You just going to waste some runtime if you do not need services
provided by ASPX.

So here is use-case scenarios so you would get better understanding.

1. Create HTML page that has couple buttons and grid on it.. ----- Use ASPX
page.. It's easy to manipulate those Web controls ASPX page creates for
you...

2. Get an image from the database using imageId ---- Use HTTP handler.
You do not need ASPX page... since you do not have webcontrols..
Just write an myimage.axd with will interpret parameter ImageId, get binary
data and send to browser using Response.BinaryWrite... call it in your HTML
pages <img src="myimage.axd?imageid=1">

Of course you could have written aspx page in case 2 but you would waste
some run time..
Or you could have written a HTTP handler in case 1 but it would remind old
asp style of writing application.

---------------------------------------------------------------------------
HTTPModule is totally different and allows you to tap into request before or
after page is processed...
Use-case scenarios...
1. Url rewrite
2. Security like checking that user have used SSL where needed..
3. IP banning...

George.


"David" <a...@asd.com> wrote in message
news:sq2dnd1OLOzCkpvV...@brightview.com...

David

unread,
Apr 16, 2008, 11:35:52 AM4/16/08
to
Thanks George - that explains it very well indeed.

David

George Ter-Saakov

unread,
Apr 16, 2008, 11:49:41 AM4/16/08
to
You are absolutely right..
It could have been done in Page_Load event....
But I hope you know an answer already (still going to repeat it).

You would waste some CPU runtime by asking (by doing it as an aspx page) to
provide all services ASPX page providing and not utilizing them..

ASPX page have a so called "Page cycle" which is a sequence of bunch of
methods called at certain time.You do not need all that here... Hence a
HTTPhandler....

PS: My advice to get familiar with "page cycle" google it or here
http://www.c-sharpcorner.com/UploadFile/ShanthiM/ASP.NETPageLifeCycle03092005001005AM/ASP.NETPageLifeCycle.aspx?ArticleID=600150a4-56e8-4f38-bfc0-319a85b81a90

George.

"David" <a...@asd.com> wrote in message

news:zaidne8Zg_2zh5vV...@brightview.com...

Joe

unread,
Apr 18, 2008, 10:38:28 AM4/18/08
to
Sorry for the late reply. I ended up using the Application_BeginRequest to
re-write the URL.

Thanks,
Joe

"Steven Cheng [MSFT]" <stc...@online.microsoft.com> wrote in message
news:0RayX%236nIH...@TK2MSFTNGHUB02.phx.gbl...

Steven Cheng [MSFT]

unread,
Apr 20, 2008, 11:00:32 PM4/20/08
to
Thanks for your followup Joe,

Glad that you've found out the solution.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

--------------------
>From: "Joe" <jbas...@noemail.noemail>
>References: <exlL9fAn...@TK2MSFTNGP03.phx.gbl>
<5JuZjjdn...@TK2MSFTNGHUB02.phx.gbl>
<0RayX#6nIHA...@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: HttpHandler
>Date: Fri, 18 Apr 2008 10:38:28 -0400

0 new messages