Main Page | Report this Page
.NET DotNet Forum Index  »  ASP.NET Forum  »  How to get a handler for a path...
Page 1 of 1    

How to get a handler for a path...

Author Message
Marvin Landman...
Posted: Sat Oct 24, 2009 5:01 am
Guest
Hi,

Server.Transfer and Execute only accept Pages but I would like to be
able to execute handlers of any type.

I am able to do that using the IHttpHandler and IHttpHandlerFactory
interfaces but I am unable to obtain a handler for any given path.

I could use HttpHandlersSection for classic mode although I still had to
find a match manually but integrated configuration is not exposed and by
default I can't even read applicationHost.config.

Please help me getting a handler for any given path.

Thanks.

Best regards,
Marvin
 
bruce barker...
Posted: Sat Oct 24, 2009 5:33 pm
Guest
there are a couple issues. when you call server transfer, you are in the
Process method of the current running page handler. when server transfer
loads the next page, the handler knows it inside a running request, and
has code to support that state.

other handlers may not work. if they are your own, then you can load
them and call a special entry point.

-- bruce (sqlwork.com)

Marvin Landman wrote:
Quote:
Hi,

Server.Transfer and Execute only accept Pages but I would like to be
able to execute handlers of any type.

I am able to do that using the IHttpHandler and IHttpHandlerFactory
interfaces but I am unable to obtain a handler for any given path.

I could use HttpHandlersSection for classic mode although I still had to
find a match manually but integrated configuration is not exposed and by
default I can't even read applicationHost.config.

Please help me getting a handler for any given path.

Thanks.

Best regards,
Marvin
 
Marvin Landman...
Posted: Sun Oct 25, 2009 2:31 pm
Guest
I understand that there are problems but also note that Server.Transfer
only works for System.Web.UI.Page instances not any handlers.

I actually would like to know if the given path is mapped to my handler
and if so I would execute it kind of a subrequest.

Thanks.

Marvin

bruce barker wrote:
Quote:
there are a couple issues. when you call server transfer, you are in the
Process method of the current running page handler. when server transfer
loads the next page, the handler knows it inside a running request, and
has code to support that state.

other handlers may not work. if they are your own, then you can load
them and call a special entry point.

-- bruce (sqlwork.com)

Marvin Landman wrote:
Hi,

Server.Transfer and Execute only accept Pages but I would like to be
able to execute handlers of any type.

I am able to do that using the IHttpHandler and IHttpHandlerFactory
interfaces but I am unable to obtain a handler for any given path.

I could use HttpHandlersSection for classic mode although I still had
to find a match manually but integrated configuration is not exposed
and by default I can't even read applicationHost.config.

Please help me getting a handler for any given path.

Thanks.

Best regards,
Marvin
 
Allen Chen [MSFT]...
Posted: Sun Oct 25, 2009 7:59 pm
Guest
Hi Marvin,

Quote:
Please help me getting a handler for any given path.

Is my understanding correct that you want to have an HttpHandler to handle
all requests? If so you can config the varb and path as "*", like below:

<system.webServer>
...

<handlers>
...

<add name="mycustomhandler" verb="*" path="*"
type="YourHandlerClass" />

If it's not what you need could you clarify what you mean by "a handler for
any given path"?

Regards,
Allen Chen
Microsoft Online Support

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:
msdnmg at (no spam) microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. 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/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Allen Chen [MSFT]...
Posted: Mon Oct 26, 2009 11:22 pm
Guest
Hi Marvin,

Quote:
Thank you for your reply.

I have a hanlder that can handle any path but I let my users chose what
files, extensions (or wildcard) they want to handle.

So I don't know what they have configured.

And I would like to be able to get the actually configured handler for
any given path/verb so that I can know if that's mine and handle specially.

I'm a little confused. Is my understanding correct that:

1. You have control over the HttpHandler class only.
2. You don't know how the users of HttpHandler set their web.config and CAS
of server machine.
3. With above restrictions, you still want your HttpHandler to handle all
requests.

Am I right? If so as far as I know there's no way to do so because it's
insecure. If my understanding is wrong could you please clarify what you
want to do?

BTW, have you tried HttpModule? Can it solve this issue?

http://msdn.microsoft.com/en-us/library/aa719858(VS.71).aspx

Regards,
Allen Chen
Microsoft Online Support
 
Allen Chen [MSFT]...
Posted: Wed Oct 28, 2009 8:51 pm
Guest
Hi Marvin,

Quote:
I don't want to handle all requests I just want to let my users decide
what requests they handle but later I need to know if a given path is
handled by my hander because my system has a sub-request like feature
that needs this information.

Thanks for your reply. Could you elaborate what your "sub-request like
feature" is? Why it needs to know whether your handler can handle a given
path? We probably can work out another approach to solve the underlying
problem if you could provide more detailed information.

BTW, is it possible to send a HTTP reqeust to that given path in your
"sub-request like feature"? By checking the HTTP response we can know
whether it's handled by your handler. (in your HttpHandler, you can add
specific HTTP header or return specific content in response to notify that
it's handled by your handler)

Regards,
Allen Chen
Microsoft Online Support
 
Allen Chen [MSFT]...
Posted: Sun Nov 01, 2009 9:04 pm
Guest
Hi Marvin,

Quote:
I only need to know if a given path is handled by my handler and throw
an exception (or present an error) otherwise.

Thanks for your clarification. Then how about this simple approach
mentioned in my previous reply:

Is it possible to send a HTTP reqeust to that given path in your
"sub-request like feature"? By checking the HTTP response we can know
whether it's handled by your handler. (in your HttpHandler, you can add
specific HTTP header or return specific content in response to notify that
it's handled by your handler)

You can use WebClient to request that path and check the response. Can it
solve this issue?

Regards,
Allen Chen
Microsoft Online Support
 
Allen Chen [MSFT]...
Posted: Wed Nov 04, 2009 12:01 am
Guest
Hi Marvin,

Quote:
What I want to avoid is executing handlers other than mine. In fact I
don't have to execute my handler but even if I execute it that is not a
problem. By making a request I would execute any handler on that URL.

Thanks for your update. I believe we can move forward if you could clarify
this point:

You mentioned:

Quote:
because my system has a sub-request like feature
that needs this information.

What is your "system"? Is it an ASP.NET application? Does it run on the web
server or another machine?

We probably can work out a solution if this point is clarified.

Regards,
Allen Chen
Microsoft Online Support
 
Allen Chen [MSFT]...
Posted: Thu Nov 05, 2009 2:09 am
Guest
Hi Marvin,

Quote:
This is a development framework based on the ASP.NET infrastructure and
intended to be used by web applications.

Thanks for update. Do you mean you want to check the path in the same
application? If it is you probably can try the following approach if
reflection is an acceptable option:


protected void Page_Load(object sender, EventArgs e)
{
// Given path
string vp = "~/1.allenchen";
var virtualpath =
Assembly.GetAssembly(typeof(HttpApplication)).CreateInstance("System.Web.Vir
tualPath", false, BindingFlags.Instance | BindingFlags.NonPublic, null, new
object[] { vp }, CultureInfo.CurrentCulture, null);
// Use MapHttpHandler method for classic mode,
MapIntegratedHttpHandler for integrated mode
// If you test it in ASP.NET Web Development server it may
throw exception.
// Please publish it to IIS and use Integriated mode to test
MethodInfo mi =
HttpContext.Current.ApplicationInstance.GetType().GetMethod("MapIntegratedHt
tpHandler", BindingFlags.Instance | BindingFlags.NonPublic);

var o = mi.Invoke(HttpContext.Current.ApplicationInstance, new
object[] { HttpContext.Current, "GET", virtualpath,
Request.ServerVariables["PATH_TRANSLATED"], false,false });

if (!(o is MyHandler))
{
throw new Exception("Not handled by MyHandler");
}

}

Please test it to see if it can solve this issue.

Regards,
Allen Chen
Microsoft Online Support
 
Allen Chen [MSFT]...
Posted: Tue Nov 10, 2009 10:43 pm
Guest
Hi Marvin,

Quote:
This is a development framework based on the ASP.NET infrastructure and
intended to be used by web applications.

Can my suggestion solve this issue?

Regards,
Allen Chen
Microsoft Online Support
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Dec 11, 2009 2:47 am