c#


HttpResponse - how to set status code depends on PushStreamContent execution result


I write data to http response using PushStreamContent class. I need to retrieve an appropriate HTTP status code depends on result of onStreamAvailable delegate execution. Here is an example code:
[HttpGet]
public HttpResponseMessage Get(int id)
{
try
{
HttpResponseMessage response = this.Request.CreateResponse();
response.Content = new PushStreamContent((Stream outputStream, HttpContent content, TransportContext context) =>
{
try
{
throw new Exception("Just an exception");
response.StatusCode = HttpStatusCode.OK;
}
catch (Exception ex)
{
using (StreamWriter sw = new StreamWriter(outputStream))
{
sw.WriteLine(ex.Message);
sw.Flush();
}
response.StatusCode = HttpStatusCode.InternalServerError;
}
});
return response;
}
catch (Exception ex)
{
return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
}
}
The example above always retrieves status code 200 (Ok). How I can fix it?

Related Links

Custom msmq trace listener
jQuery white label theme widget auto reload
mpi packet for c# paralleling program
The type of name space “” could not be found VS2013
C# Create a Truncated Collection with LINQ [duplicate]
How to get User Control in listbox data template item
Start from scratch MVC [closed]
using checkbox to enable textbox
Why are Anchor properties not being honored within dynamically created nested components?
Dataset data is different that stored procedure
Zip file being accessed by multiple user - Mem out of exception issue
Why I can't use FileStream in windows store app [duplicate]
Save file to server viaWCF
T4 runtime template path specification
JSON.NET CustomCreationConverter with nested objects
Can a C# Interface require or dictate a specific class?

Categories

HOME
youtube-api
url
azure-active-directory
typo3
ns2
locale
cxf
packet
azure-database-mysql
arguments
lithium
hiveql
artifactory
obd-ii
elastalert
virtualenv
expo
mbed
element
javascript-debugger
jinja2
jsfiddle
hapijs
indri
printf
aiml
django-rest-auth
udeploy
gomobile
cherrypy
vala
klipfolio
gnu-screen
google-drive-android-api
concatenation
rvm
expressionengine
pydub
csproj
foxpro
tikz
visual-studio-debugging
openvms
apache-falcon
sdl-2
kofax
maven-2
mediastream
server-side-swift
icu
rbac
vertical-alignment
irr
ocamlbuild
hierarchical-clustering
serialversionuid
perldoc
htop
therubyracer
alarmmanager
xcode7.1
jcalendar
stdlist
code-translation
apache2-module
tvp
serial-communication
bootstrap-tabs
syncano
borland-c++
dcg
data-representation
mergecursor
data-quality-services
nsq
alpha-beta-pruning
vundle
visual-c#-express-2010
debuggervisualizer
hotlinking
lettuce
infor-eam
mobile-robots
jython-2.5
pyxplot
stringstream
leap-year
nsautoreleasepool
nx
dnsbl
big-endian
winrt-async
systrace
django-1.4
mysql-connector
funambol
sipdroid
large-data-volumes
vista64

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App