DEBUG and RELEASE modeIf i have a route in my application called e.g.
https://localhost/api/Foo/Bar/ then GET, POST, DELETE and PUT work.
But if i have
https://localhost/api/Foo/Bar/Something then GET, POST work, DELETE and PUT does not work.
If i look at teh "ROUTES" property, all the routes are correct...
Is this expected behaviour = ?
*Make an Nancy module with the route:
Put["/Foo/Bar/Put1"] = _ => DoSomething();
DELETE["/Foo/Bar/Delete1] = _ => DoSomething();
and they will not be called. Buut get and post will.
ASP.NET MVC5, with OWIN and Cookies auth.
In my project this works with the same packages and .NET 4.6.2.
Nancy is set up like so
app.Map("/api", builder =>
{
builder.UseNancy(options =>
{
// ...
});
builder.UseStageMarker(PipelineStage.MapHandler);
});
One of my async DELETE routes is
/api/transaction/123/horseprofile/videolink/456
/api is from the owin mapping
/transaction/{id:int}/horseprofile is the module path
/videolink/{videoId:int} is the route itself
Great xt0rted... i was missing builder.UseStageMarker(PipelineStage.MapHandler); !!!
i had app.UseStageMarker(PipelineStage.MapHandler);
Dammit. The "builder.UseStageMarker(PipelineStage.MapHandler);" did help the routing. But then it messes up the session for the http context.
I am using redis session based cache, and adding:
app.Use((context, next) =>
{
var httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName);
httpContext.SetSessionStateBehavior(SessionStateBehavior.Required);
return next();
});
Allowed the session to be available in Nancy HttpContextBase from the GetOwinEnviroement.
But this no longer works after adding the UseStageMarker to the Map.
Before i had the UseStageMarker on the App and this works fine., but the PUT and DELETE do not work with paths that have more than 3 "/"'s.
Any ideas?
Have you tried adding a second stage marker after Nancy to make sure it runs after the session state has been aquired?
Something like this:
app.Use((context, next) =>
{
var httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName);
httpContext.SetSessionStateBehavior(SessionStateBehavior.Required);
return next();
});
app.UseStageMarker(PipelineStage.MapHandler);
app.UseNancy();
app.UseStageMarker(PipelineStage.PostAcquireState);
Hi k
Thats really great, thanks!
I will try first thing tomorrow. The interesting thing is the “UseNancy()” and stage is in the Map. It needs to be otherwise the mvc site doesn’t work.
Still I will see if it helps :-)
Hi Again
I have now tried all the combinations i could think off.
I have had the SetSessionStateBehavior inside of the branch and out side of it.
The rule is always this. If i do not have:
branch.UseStageMarker(PipelineStage.MapHandler); then the PUT and DELETE do not work when there is .e.g api/foo/bar/something. But do work when the address is api/foo/bar., The GET and POST always work. However the Session does resolve.
If i do have branch.UseStageMarker(PipelineStage.MapHandler); then the PUT and DELETE alone with GET and POST work for all paths, However the Session does not resolve.
I have even tried to specify this mush (inluding combinations with and without the UseStageMarker.
The Barnch MUST have a branch.UseStageMarker(PipelineStage.MapHandler); otherwise it does note resolve for the 3 "/"'s in PUT and DELETE:
It is very weird that the GET and POST work, but not the PUT and DELETE!...
app.Use((context, next) =>
{
var httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName);
httpContext.SetSessionStateBehavior(SessionStateBehavior.Required);
return next();
});
app.UseStageMarker(PipelineStage.MapHandler);
app.Map("/api", branch =>
{
branch.UseStageMarker(PipelineStage.MapHandler);
branch.UseNancy(options =>
{
options.Bootstrapper = new ApiBootstrapper(container);
options.PerformPassThrough = context => context.Response.StatusCode == HttpStatusCode.NotFound;
});
branch.UseStageMarker(PipelineStage.PostAcquireState);
});
app.UseStageMarker(PipelineStage.PostAcquireState );
Funny. I have even tried with and all paths work, but not httpcontextbase session:

However the sessions work here, but not the PUT and DELETE paths api/foo/bar/something:

This also does not work with cache session but the routes do work. Changing "app" with "branch" also does not work...

Hmm. This sounds like an IIS issue. PUT and DELETE not working is a classic WebDAV issue. See https://stackoverflow.com/a/29885790/682105:
<modules>
<remove name="WebDAVModule"/>
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
I can try it, but WebDAV is not enabled.
And the DELETE and PUT do work. Only not with to many ´ssgments in the route. GET and POST do not have the Segment issue...
Sorry.
No cigar. No luck.
This is still the only way the session works but the POST and DELETE with "many" segments do not work.

The question is would then be. Why does GET and POST work, but not PUT and DELETE.
It there a bug in this.
Or is there a issue in the httpcontext session resolving with the branch owin context.
I think the next step is for me to make a bare minimum project that replicates.
I think the next step is for me to make a bare minimum project that replicates.
Yes, that would be awesome.
The question is would then be. Why does GET and POST work, but not PUT and DELETE.
It there a bug in this.
There should be absolutely no limit to how many "segments" you can have, or any connection between the route's segments and the HTTP method. At least not in Nancy.
You mentioned
and they will not be called. Buut get and post will.
Does that mean you've set breakpoints and verified that they're not called? What's the response you get back?
It sounds an awful lot like IIS is snatching the requests before they reach Nancy, because there's no special handling of PUT or DELETE in Nancy.
Hi
I have put breakpoints in the Module with the route. The get, post, put and delete are in the same module. This is where i can see that the get and post gets called, but not the put/delete.
I can also see in the browser console that a 404 is returned..
I can’t see that the IIS is snatching the app has a map for /api/ goes to Nancy and I think the Nancy passthrough on the app mapping is returning the 404.
I will make sure when I make the test solution.
Please give me to the weekend... I have to finish some other stuff first....
Hej Kristian. HĂĄber alt er vel :-)
I have made a very simple autofac, nancy mvc5 project with OWIN. I began adding a inproc session, but when i span the application up the get and post work, but not the delete and put.
Maybe this should be the focus, and then the session stuff as part 2.? Tehh nancy module is in the class Module1.
I have used the chrome arc app for rest testing.
As stated all the GET and POSTs work, buit none of the DELETE and PUT work.
Have i done something completely silly/wrong?
Thanks for your time. VS2017 solution attached. Startup has the bootstrapping with owin.
Nancy does not handle DELETE or PUT any differently than GET or POST. There's especially no artificial limitations imposed by Nancy on the number of route segments you can use with those two verbs.
Like @khellang mentioned https://github.com/NancyFx/Nancy/issues/2820#issuecomment-342415875 this is a web server thing (evident by the fact that you are getting an IIS error page and not a Nancy error page)
I took your sample, added this solution https://forums.asp.net/t/1961593.aspx?DELETE+PUT+verbs+result+in+404+Not+Found+in+WebAPI+only+when+running+locally and I can run the DELETE and PUT routes without any problems

I'll close this now. I consider this to be done and not related to Nancy
Thanks
Thanks. It did the trick!
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Most helpful comment
Nancy does not handle
DELETEorPUTany differently thanGETorPOST. There's especially no artificial limitations imposed by Nancy on the number of route segments you can use with those two verbs.Like @khellang mentioned https://github.com/NancyFx/Nancy/issues/2820#issuecomment-342415875 this is a web server thing (evident by the fact that you are getting an IIS error page and not a Nancy error page)
I took your sample, added this solution https://forums.asp.net/t/1961593.aspx?DELETE+PUT+verbs+result+in+404+Not+Found+in+WebAPI+only+when+running+locally and I can run the
DELETEandPUTroutes without any problemsI'll close this now. I consider this to be done and not related to Nancy
Thanks