Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentType null #51

Closed
snblackout opened this issue Dec 14, 2013 · 2 comments
Closed

ContentType null #51

snblackout opened this issue Dec 14, 2013 · 2 comments

Comments

@snblackout
Copy link

Using V2 line 153 of CacheOutputAttribute.cs:

_webApiCache.Add(cachekey + Constants.ContentTypeKey, actionExecutedContext.Response.Content.Headers.ContentType.MediaType, cacheTime.AbsoluteExpiration, baseKey);

Headers.ContentType = null.

I'm decorating my GET function like:

HttpGet
ActionName("GetThis")
CacheOutput(ServerTimeSpan:=5, ClientTimeSpan:=0)
Public Function DoGetThis(ByVal guid As String) As HttpResponseMessage

Returning:
New HttpResponseMessage() With {.Content = New JsonContent(New With {Key .Success = True, Key .Message = "Success", .NowPlaying = data})}

data is my own business logic class.
JsonContent is from http://stackoverflow.com/questions/14231877/how-to-return-json-object-on-web-api-controller

Am I doing something wrong?

@filipw
Copy link
Owner

filipw commented Dec 14, 2013

yes, the SO example doesn't set the content type header correctly. Set it
to application/json or use different method of creating JSON response (i.e.
JsonResult : IHttpActionResult)

On 15 December 2013 00:25, snblackout notifications@github.com wrote:

Using V2 line 153 of CacheOutputAttribute.cs:

_webApiCache.Add(cachekey + Constants.ContentTypeKey,
actionExecutedContext.Response.Content.Headers.ContentType.MediaType,
cacheTime.AbsoluteExpiration, baseKey);

Headers.ContentType = null.

I'm decorating my GET function like:

Public Function DoGetThis(ByVal guid As String) As HttpResponseMessage

Returning:
New HttpResponseMessage() With {.Content = New JsonContent(New With {Key
.Success = True, Key .Message = "Success", .NowPlaying = data})}

data is my own business logic class.
JsonContent is from
http://stackoverflow.com/questions/14231877/how-to-return-json-object-on-web-api-controller

Am I doing something wrong?


Reply to this email directly or view it on GitHubhttps://github.com//issues/51
.

@snblackout
Copy link
Author

Thank you, I just decided to ditch the JsonContent from the SO article and just did:

Return Request.CreateResponse(Of MyClass)(HttpStatusCode.OK, New MyClass())

That way your OutputCache is working fine and I can still return my own class structure back over the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants