2

I'm trying to configure an OpenRasta resource to respond a HTTP HEAD operation. I already tried to use UriName, different method names and signatures, but I couldn't find a solution yet. This is the configuration code that I used:

ResourceSpace.Has.ResourcesOfType<Stream>()
                 .AtUri("/assets/{providerCode}/?type={type}")
                 .HandledBy<AssetHandler>();

And this is the method at the AssetHandler:

[HttpOperation(HttpMethod.HEAD)]
public OperationResult Head(string providerCode, int type)
{
    var asset = assetService.GetAssetAtCDN(providerCode, type);
    if (asset == null) return new OperationResult.NotFound();

    return new OperationResult.Found { RedirectLocation = new Uri(asset.Url) };
}

Sample request:

HEAD http://localhost:63483/assets/PygvCaOfK353etajBlbd/?type=4 HTTP/1.1
Accept-Encoding: gzip,deflate
Host: localhost:63483

Response:

HTTP/1.1 405 Method Not Allowed
Server: ASP.NET Development Server/9.0.0.0
Date: Mon, 31 Oct 2011 17:40:39 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Length: 0
Connection: Close

And at OpenRasta log:

DEBUG Entering OpenRastaRewriterHandler: Rewriting to original path e:
DEBUG Entering OpenRastaIntegratedHandler: Request for http://localhost:63483/assets/PygvCaOfK353etajBlbd/?type=4 e:
DEBUG Found 0 operation(s) with a matching name. e:
DEBUG Found 0 operation(s) with matching [HttpOperation] attribute. e:
INFO Executing OperationResult OperationResult: type=MethodNotAllowed, statusCode=405. e:
INFO No response codec was searched for. The response entity is null or a response codec is already set. e:
DEBUG There was no response entity, not rendering. e:
DEBUG Writing http headers. e:
DEBUG Exiting OpenRastaIntegratedHandler e:
DEBUG Exiting OpenRastaRewriterHandler e:

This is the clean version of the web.config:

  <system.web>
    <pages>
      <namespaces>
        <add namespace="OpenRasta.Web"/>
        <add namespace="OpenRasta.Web.Markup"/>
        <add namespace="OpenRasta"/>
      </namespaces>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
    </pages>
    <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
      <!--OpenRasta-->
      <add verb="*" path="*.rastahook" type="OpenRasta.Hosting.AspNet.OpenRastaHandler, OpenRasta.Hosting.AspNet"/>
    </httpHandlers>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <!--OpenRasta-->
      <add name="OpenRastaModule" type="OpenRasta.Hosting.AspNet.OpenRastaModule, OpenRasta.Hosting.AspNet"/>
    </httpModules>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ScriptModule"/>
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="OpenRastaModule" type="OpenRasta.Hosting.AspNet.OpenRastaModule, OpenRasta.Hosting.AspNet"/>
    </modules>
    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <remove name="ScriptHandlerFactory"/>
      <remove name="ScriptHandlerFactoryAppServices"/>
      <remove name="ScriptResource"/>
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="OpenRastaHandler" verb="*" path="*.rastahook" type="OpenRasta.Hosting.AspNet.OpenRastaHandler, OpenRasta.Hosting.AspNet"/>
    </handlers>
  </system.webServer>
aelesbao
  • 503
  • 4
  • 14

1 Answers1

0

You can use ResourcesNamed for this:

ResourceSpace.Has.ResourcesNamed("head")
             .AtUri("/assets/{providerCode}/?type={type}")
             .HandledBy<AssetHandler>();
Rob Segerink
  • 106
  • 1
  • 3
  • thanks, but it didn't worked! I also tried to change the ResourcesOfType() to ResourcesOfType(), but the error is the same... The most strange thing is that if I switch the HEAD operation with a GET, the handler is found. – aelesbao Oct 31 '11 at 19:31
  • Hmm, that's strange I use it myself for head requests, your uri looks a little bit strange, /?type={type}, shouldn't be that /type={type} ? What does you httphandler web.config openrasta settings look like ? – Rob Segerink Oct 31 '11 at 20:01
  • Hmm, seems nothing wrong with you web.confg, did you try a head request without parameters in the uri? – Rob Segerink Oct 31 '11 at 20:21
  • 1
    Rob, indeed, the problem was not related to OpenRasta... Someone configured the project to build on a different path than /bin, so I could never see the changes when it was compiled... ¬¬ Anyway, thank you very much for the help! – aelesbao Oct 31 '11 at 21:16