R – What are the rules around httpHandler paths in ASP.NET

asp.nethttphandlersharepoint

Is there a good resource for the rules around how the httpHandler path property is used?

I am seeing mixed results for when my handler is called in different environments, so let me explain…

I want to allow for a URL such as:

http://mysite/_layouts/myCompany/rest/myservice.svc/param1/param2

I would like to invoke my handler only under "myCompany" folder/link so I put the following web.config file in the corresponding folder so as not to affect the rest of the application. This works on some machines, but not on others:

<configuration>
    <system.web>
        <httpHandlers>
            <add verb="*" path="myservice.svc" type="..." validate="false"/>
        </httpHandlers>
    </system.web>
</configuration>

Now, I've got to admit that I was a little surprised that this worked since it basically had to find the "myservice.svc" out of the "rest/myservice.svc/param1/param2" relative path, but it did find it – but only on two of my three test machines. So, I tried the following on the machine that it failed on:

<add verb"*" path="rest/myservice.svc/*/*" type="..." validate="false"/>

This worked a few times and is now not working. Being the logical type it really bothers me that after a bit if diligence I cannot explain this, but I haven't been able to get it to work again. See also this similar Stack Overflow question.

Note that the following does work, but it makes me resort to query string variables to provide parameters which is not ideal.

<add verb"*" path="rest/myservice.svc/*" type="..." validate="false"/>

I looked into the parent web.config files along the way on two machines that give different results to see how they define any httpHandlers and nothing popped out as a problem.

So, I'm looking for an understanding of how this path is utilized.

For what it's worth, this is running in a SharePoint site (hence the "sharepoint" tag on this question) and I am using this to provide REST (simple "text/xml") instead of SOAP. I do not want to use full blown WCF because that rocks the boat a little too much many installations of SharePoint so I'm using an HTTP Handler instead.

In addition, the error I'm getting is the following:

virtualPath   at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) 
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) 
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) 
   at System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) 
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

Best Answer

An answer is still welcome, but here I found a simple workaround. So simple it bothers me that I didn't think of it before...

Since I own the folder/url from a certain point, I can just make sure that everything goes through my handler:

<add verb"*" path="*" type="..." validate="false"/>

How simple can it get :-S.

A side benefit of this is that I can better report an error for improper URLs. I may decide to use a handler factory instead of a handler; then the only change is the type that is specified.

Related Topic