On Dev PC getting back error json resource correctly, on IIS7.5 getting back html error page.

258 views
Skip to first unread message

Rob

unread,
May 10, 2011, 12:11:38 AM5/10/11
to OpenRasta
I am using newtonsoft json library and have a openrasta codec for it
and its been working great.

I have been running tests.
I am sending my resource with a corrupt date field "x2011/01/11" as
part of a test.
This produces an exception from the NewtonsoftJsonCodec I am using. as
I expected.
This exception is being propogated into ServerErrors by OpenRasta as
expected.
I have a pipeline contributor that collects servererrors and modifies
the OperationResult.

Pipeline contributor registers as follows.
pipelineRunner.Notify(CollectResourceErrors)
.After<KnownStages.IOperationResultInvocation>()
.And.Before<KnownStages.ICodecResponseSelection>();

This all works fine on my local developer box.
I get back json from resource from the Post to the resource with the
errors in my response resource.

I have deployed this to IIS7.5 and started testing against that.
On IIS7.5 I am getting html error response to this error. [it is not
json]
"405 - HTTP verb used to access this page is not allowed"

Since discovering this problem I installed elmah 1.2 on the IIS7.5 as
well just in case something was leaking out of OpenRasta by different
path. This does not seem to be the case though.

I have tried to include all the info needed.
Could I have a configuration difference on IIS7.5 thats causing this
difference.

Thanks for any tips or suggesions,
Rob.



Sebastien Lambla

unread,
May 10, 2011, 3:56:24 AM5/10/11
to open...@googlegroups.com
Can you let me know what http method and what response status code you're returning?

I am <sick to death> of IIS unpredictable behaviour, each version is causing more and more unrelated and random messages. <sigh>

Rob

unread,
May 10, 2011, 7:06:48 PM5/10/11
to OpenRasta
I am doing a POST to http://domain/ws/v1/sites/33/assetmeterreading.
I am only modifying one field in the json resource data. It works with
a valid date field.

I am getting backing on IIS 7.5 "HTTP/1.1 405 Method Not Allowed" in
Content-Type "text/html"
In the body and title shows "405 - HTTP verb used to access this page
is not allowed."

On my local development box I get "HTTP/1.1 405 Method Not Allowed"
Content-Type "application/json; charset=utf-8"
I do get back my resource with the error attached.

Is that what you were after ?

I am about to try the ElmahLogger i fouind some write up of online and
see if i can get more logging out of OpeNRasta on IIS7.5.

Thanks for any tips,
Robin.

Rob

unread,
May 10, 2011, 9:24:26 PM5/10/11
to OpenRasta
I captured a bit more information - by creating an ILogger and feeding
it through Elmah, for want of a better trace watcher.
Thought it might help so am posting, it does not look like something
is particularly wrong to me.
The calls are newest at top here.

Type Error
Debug Writing http headers. Details…
Debug Setting Content-Length to 147 Details…
Debug Codec NewtonsoftJsonCodec selected. Details…
Info Selected codec NewtonsoftJsonCodec out of 1 codecs for entity of
type ResourceListWrapper`1 and negotiated media type application/json;
q=0.5. Details…
Info Executing CollectResourceErrors Modified OperationResult:
type=MethodNotAllowed, statusCode=405. Details…
Exception Got the error "An expected field containing Date
information could not be read as a date.". Details…
Exception Got type MetricsAndErrors "moo". Details…
Exception Got currentResource
"TrakkaShell.Resources.ResourceListWrapper`1[TrakkaShell.Resources.AssetMeterReadingImport]".
Details…
Exception Got context.OperationResult "OperationResult:
type=MethodNotAllowed, statusCode=405". Details…
Exception Got server error "Exception: System.FormatException: The
string was not recognized as a valid DateTime. There is an unknown
word starting at index 0. at System.DateTime.Parse(String s,
IFormatProvider provider, DateTimeStyles styles) at
Newtonsoft.Json.Converters.IsoDateTimeConverter.ReadJson(JsonReader
reader, Type objectType, Object existingValue, JsonSerializer
serializer) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json
\Converters\IsoDateTimeConverter.cs:line 131 at N Details…
Info Executing CollectResourceErrors before OperationResult:
type=MethodNotAllowed, statusCode=405. Details…
Info Executing OperationResult OperationResult:
type=MethodNotAllowed, statusCode=405. Details…
Format The string was not recognized as a valid DateTime. There is an
unknown word starting at index 0. Details…
Info Operation Handler`1::Post(AssetMeterReadingImport newresource)
selected with 1 required members and 0 optional members, with codec
NewtonsoftJsonCodec with score 0. Details…
Info Operation Handler`1::Post(AssetMeterReadingImport newresource)
selected with 1 required members and 0 optional members, with codec
NewtonsoftJsonCodec with score 0. Details…
Info Operation Handler`1::Post(Int32 siteID, IEnumerable`1 resources)
selected with 2 required members and 0 optional members, with codec
NewtonsoftJsonCodec with score 1. Details…
Info Operation Handler`1::Post(Int32 siteID, IEnumerable`1 resources)
selected with 2 required members and 0 optional members, with codec
NewtonsoftJsonCodec with score 1. Details…
Debug Found 0 operation(s) with matching [HttpOperation] attribute.
Details…
Debug Found 3 operation(s) with a matching name. Details…





On May 11, 9:06 am, Rob <robin.lui...@gmail.com> wrote:
> I am doing a POST tohttp://domain/ws/v1/sites/33/assetmeterreading.

Sebastien Lambla

unread,
May 11, 2011, 4:58:29 AM5/11/11
to open...@googlegroups.com
Hmmm. In this case the 405 may be justified, in the sense that your codec throws errors, so openrasta will try and match the next method with a matching signature. If none of them can work properly, there are no methods that can be executed on the target resource, and we send back a 405.

You first should make sure that your codec throwing does result in a 401 (probably something we should do in the fx ourselves, if all operations fail and all fail because the codec throws).

Second, what html page is that? Is this the one in OpenRasta or the one from IIS? I assume it's the latter, as the use of "verb" to mean "method" is something typical of MS software. If that is the case, it would seem that the "friendly erorrs" of iis or aspx is kicking in, overriding whatever we send down.

So I'd deactivate that IIS "feature".

> -----Original Message-----
> From: open...@googlegroups.com [mailto:open...@googlegroups.com]
> On Behalf Of Rob
> Sent: 11 May 2011 02:24
> To: OpenRasta
> Subject: [openrasta] Re: On Dev PC getting back error json resource
> correctly, on IIS7.5 getting back html error page.
>

> I captured a bit more information - by creating an ILogger and feeding it
> through Elmah, for want of a better trace watcher.
> Thought it might help so am posting, it does not look like something is
> particularly wrong to me.
> The calls are newest at top here.
>
> Type Error

> Debug Writing http headers. Details.
> Debug Setting Content-Length to 147 Details.
> Debug Codec NewtonsoftJsonCodec selected. Details.


> Info Selected codec NewtonsoftJsonCodec out of 1 codecs for entity of
> type ResourceListWrapper`1 and negotiated media type application/json;

> q=0.5. Details.


> Info Executing CollectResourceErrors Modified OperationResult:

> type=MethodNotAllowed, statusCode=405. Details.


> Exception Got the error "An expected field containing Date

> information could not be read as a date.". Details.
> Exception Got type MetricsAndErrors "moo". Details.


> Exception Got currentResource
> "TrakkaShell.Resources.ResourceListWrapper`1[TrakkaShell.Resources.Asset
> MeterReadingImport]".

> Details.
> Exception Got context.OperationResult "OperationResult:
> type=MethodNotAllowed, statusCode=405". Details.


> Exception Got server error "Exception: System.FormatException: The
> string was not recognized as a valid DateTime. There is an unknown word
> starting at index 0. at System.DateTime.Parse(String s, IFormatProvider
> provider, DateTimeStyles styles) at
> Newtonsoft.Json.Converters.IsoDateTimeConverter.ReadJson(JsonReader
> reader, Type objectType, Object existingValue, JsonSerializer
> serializer) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json

> \Converters\IsoDateTimeConverter.cs:line 131 at N Details.


> Info Executing CollectResourceErrors before OperationResult:

> type=MethodNotAllowed, statusCode=405. Details.
> Info Executing OperationResult OperationResult:
> type=MethodNotAllowed, statusCode=405. Details.


> Format The string was not recognized as a valid DateTime. There is an

> unknown word starting at index 0. Details.


> Info Operation Handler`1::Post(AssetMeterReadingImport newresource)
> selected with 1 required members and 0 optional members, with codec

> NewtonsoftJsonCodec with score 0. Details.


> Info Operation Handler`1::Post(AssetMeterReadingImport newresource)
> selected with 1 required members and 0 optional members, with codec

> NewtonsoftJsonCodec with score 0. Details.


> Info Operation Handler`1::Post(Int32 siteID, IEnumerable`1 resources)
> selected with 2 required members and 0 optional members, with codec

> NewtonsoftJsonCodec with score 1. Details.


> Info Operation Handler`1::Post(Int32 siteID, IEnumerable`1 resources)
> selected with 2 required members and 0 optional members, with codec

> NewtonsoftJsonCodec with score 1. Details.


> Debug Found 0 operation(s) with matching [HttpOperation] attribute.

> Details.
> Debug Found 3 operation(s) with a matching name. Details.

Rob

unread,
May 11, 2011, 8:59:55 PM5/11/11
to OpenRasta
Ill try to restate what is happening, to see if it helps me think
about the problem, and might make it clearer.

In my test case - the error is in the json data - its actually invalid
format json, so the json decoder is throwing an exception, which
openrasta catches and logs in servererrors.

I do have a pipeline runner as mentioned above, that looks for these
server errors and modifies the OperationResult.
This does work on local dev box, its IIS environment that is behaving
differently.

Now my servererror pipeline contributor changes the OperationResult,
whatever I set in 400,401,405 does come out as the http response in
the returned data with attached boilerplate html body content type.

So my operation result is being picked up, but the content negotiated
json form and my resource are not.

Without the pipeline contributor the error in json gets set in
servererrrors and the default 405 with html format etc comes out.

Separately....
I don't understand what you mean by match the next method ?
Is it possible to configure a secondary target method to run if first
fails ?
I cant say I have noticed this in the design yet I will look around a
bit, that could be useful to me in other contexts having a fall back
method on the same URI if the first method fails... However in this
case that doesnt help, as the handler method never gets called.

Thanks for your help so far,
Robin.

Sebastien Lambla

unread,
May 12, 2011, 6:28:23 AM5/12/11
to open...@googlegroups.com
So to answer both points. The trace you provided earlier was showing that the json codec was used, and then you end up with html being served. I am assuming it's IIS or asp.net that overrides the response resource and show a "friendly" html page. That's why I'm asking if it's a blue or a yellow page, to know which of the two is doing that.

Secondly, having a fallback handler is something that may be useful indeed and has been requested in the past, so maybe we'll implement that, it'd be a good idea. As usual, if theres a bug on github I can track it and make sure we spend some time on it (http://github.com/openrasta/openrasta-core/)

Seb

Rob

unread,
May 12, 2011, 6:11:21 PM5/12/11
to OpenRasta
I don't know what a blue error screen is from IIS but I don't believe
this is one.
[I tried a few web searches for examples but had no luck of actual
images]
I do know what a yellow one is and its definitely not that.

Attached a copy of the error as rendered by browser when i set 405
response [looks same for 401] - http://imagebin.org/153049.
Looks different for a 400 response its just one word no html "Bad
Request"

I dont see them rendered normally - I see the results via fiddler as
its a webservice client communicating with the webservice.
The service renders stuff to a browser in a view only mode I have not
created any post ability with html etc.

I am looking into the custom error settings and such on IIS now, got
side tracked yesterday.

Rob

unread,
May 12, 2011, 6:38:39 PM5/12/11
to OpenRasta
Found an example of the blue error screen you mentioned.
Was not one of those either.

On May 13, 8:11 am, Rob <robin.lui...@gmail.com> wrote:
> I  don't know what a blue error screen is from IIS but I don't believe
> this is one.
> [I tried a few web searches for examples but had no luck of actual
> images]
> I do know what a yellow one is and its definitely not that.
>
> Attached a copy of the error as rendered by browser when i set 405
> response [looks same for 401] -http://imagebin.org/153049.

Sebastien Lambla

unread,
May 12, 2011, 7:06:35 PM5/12/11
to open...@googlegroups.com
So yes, that html page is one generated by IIS. Your log shows that openrasta does its job of sending a response as json, and that IIS overrides that choice with one of its modules.

When you host things on top of asp.net, OpenRasta gives the content back to asp.net, which in turn gives it back to IIS. Both have their own modules that have the capacity to do evil things, such as overriding responses. This is probably what happens here and is a config issue.

I'm happy helping you debug what component of IIS is doing that, I'd need to know what modules you have installed and how they are configured for your site. Maybe sending the .config for the application would help.

Rob

unread,
May 12, 2011, 7:51:44 PM5/12/11
to OpenRasta
Thanks to some additional pointers from Sebastien I have this working
now.

Turns out it was IIS Custom Errors - disabling this allowed my error
response to come out properly.

However everyone says 'disable custom errors' I am on IIS 7,.5 and
there is no IIS Custom Errors section.
Under IIS 7.5 Its called IIS Error Pages, and to disable it means to
set Features Settings to "Detailed errors".

Greg Sochanik

unread,
May 13, 2011, 4:50:22 AM5/13/11
to open...@googlegroups.com
Hi,

We've had exactly the same issue recently. The best way of turning this "feature" off across the board (why would you want to return html pages when your server is not necessarily returning html? Very presumptuous!!), is to edit the %windir%/System32/inetsrv/config/applicationHost.config file, and add the following node to the system.webserver node:

<httpErrors errorMode="Detailed" existingResponse="PassThrough">
 <clear />
</httpErrors>    

I find it better practice to edit this file, rather than using the IIS7 gui, as you can see exactly what's going on. The gui has a tendancy to change multiple elements in this file in an unexpected way.

Cheers,
Greg

Sebastien Lambla

unread,
May 13, 2011, 7:06:44 AM5/13/11
to open...@googlegroups.com

Can this not be delegated to the web.config I wonder, or is that a per application setting?

 

I’m thinking that we should provide a pre-packaged hosting environment for openrasta, as a web platform installer package, so you can just add that to your IIS and then just deploy whatever openrasta stuff you want. Would people find that useful?

Greg Sochanik

unread,
May 13, 2011, 8:46:22 AM5/13/11
to open...@googlegroups.com
Theoretically yes, but one problem is that (I think) by default IIS7 seems to set settings on applications created using the gui to overrideMode="Deny", which prevents you overriding them in a config file lower down the chain. It actually throws a .NET exception if you have attempted to override them lower down.

I said I think though, so I'll double check if this is the case. I know for a fact this occurs if the applicationHost.config file settings in question are within a <location> tag.
Reply all
Reply to author
Forward
0 new messages