HttpResponseMessage(HttpStatusCode.Conflict); returns a web pagehttp://forums.asp.net/t/1798985.aspx/1?HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageThu, 07 Jun 2012 19:46:31 -040017989854960598http://forums.asp.net/p/1798985/4960598.aspx/1?HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageHttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>Using ApiController.</p> <p>&nbsp;</p> <p>public&nbsp; <span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"> <span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small">HttpResponseMessage</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"> Post()</span></span></p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">{</span></span></p> <p>&nbsp;return HttpResponseMessage <span face="Consolas" size="2" style="font-family:Consolas; font-size:small"> <span face="Consolas" size="2" style="font-family:Consolas; font-size:small">(</span></span><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small">HttpStatusCode</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">.Conflict);</span></span></p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">}</span></span></p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"></span></span>This returns a web page with the classical ASP.NET Conflict content.</span></span></p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">If I use </span></span></p> <p><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small"><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small"><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small">return</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"> </span></span><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small"><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small"><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small">new</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">&nbsp; </span></span><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small">HttpResponseMessage</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">&lt;</span></span><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small"><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small"><span face="Consolas" color="#0000ff" size="2" style="color:#0000ff; font-family:Consolas; font-size:small">string</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">&gt;(</span></span><span face="Consolas" color="#800000" size="2" style="color:#800000; font-family:Consolas; font-size:small"><span face="Consolas" color="#800000" size="2" style="color:#800000; font-family:Consolas; font-size:small"><span face="Consolas" color="#800000" size="2" style="color:#800000; font-family:Consolas; font-size:small">&quot;&quot;</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">, </span></span><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small">HttpStatusCode</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">.Conflict);</span></span></p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">I get <span size="1" style="font-size:xx-small"><span size="1" style="font-size:xx-small"><span lang="EN"></span></span></span></span></span></p> <p>HTTP/1.1 409 Conflict</p> <p>Content-Type: application/xml; charset=utf-8</p> <p>Content-Length: 47</p> <p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;string/&gt;</p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"></span></span>&nbsp;</p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">Any way I can return <span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"> <span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small"><span face="Consolas" color="#2b91af" size="2" style="color:#2b91af; font-family:Consolas; font-size:small">HttpStatusCode</span></span></span><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">.Conflict</span></span> without content at all?</span></span></p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"></span></span>&nbsp;</p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:small">Best regards!</span></span></p> 2012-05-01T21:54:44-04:004960609http://forums.asp.net/p/1798985/4960609.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>I forgot to mention this is with MVC 4 Web Api <img class="emoticon" title="Wink" border="0" alt="Wink" src="http://forums.asp.net/scripts/tiny_mce/plugins/emotions/img/smiley-wink.gif"></p> <p>&nbsp;</p> <p>Thanks!</p> 2012-05-01T22:17:00-04:004960628http://forums.asp.net/p/1798985/4960628.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>Try passing null.</p> 2012-05-01T22:54:08-04:004960840http://forums.asp.net/p/1798985/4960840.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>Try:</p> <p>throw new HttpResponseException(HttpStatusCode.Conflict);</p> <p>&nbsp;</p> <p>This is what we do for all of our no content status codes.</p> 2012-05-02T05:14:54-04:004961820http://forums.asp.net/p/1798985/4961820.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>I tried it already, passing null returns</p> <p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;Stream xsi:nil=&quot;true&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;/&gt;</p> <p>&nbsp;</p> 2012-05-02T12:19:41-04:004961823http://forums.asp.net/p/1798985/4961823.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>throw new HttpResponseException(HttpStatusCode.Conflict);</p> <p>&nbsp;</p> <p>also returns the ASP conflict Web Page.</p> 2012-05-02T12:20:40-04:004961832http://forums.asp.net/p/1798985/4961832.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>MVC4 pretends to be a good HTTP handler, but I realize&nbsp;I should stick with WCF. There is too much to overwride with MVC, but WCF is more intuitive.</p> 2012-05-02T12:22:26-04:004962031http://forums.asp.net/p/1798985/4962031.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>Try&nbsp;</p> <p>return new HttpResponseMessage&lt;string&gt;(null, HttpStatusCode.Conflict, <br> GlobalConfiguration.Configuration.Formatters.Where(x=&gt;x.SupportedMediaTypes.Any(y=&gt;y.MediaType == &quot;application/json&quot;)));</p> <p>I just cannot understand why you do not want to send back any body. Just return some useful information.</p> <p></p> <p></p> 2012-05-02T13:43:25-04:004962107http://forums.asp.net/p/1798985/4962107.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>Performance issue.</p> <p>Performance is a key driver with this project. We don't want generate data and transfer through the wire if it's not used.</p> <p>In this case, I try to create a resource that already exists.</p> <p>A status code of 409 means</p> <p>- The resource I am trying to create already exists</p> <p>- I should use GET, PUT or DELETE to read, modify or delete it.</p> <p>There is no need for any other detail, and we won't tolerate such overhead.</p> <p>I am doing an exercise comparing WCF with MVC for REST API . WCF allows me to control my HTTP requests. MVC4 is a&nbsp;model that I find harder and harder fit in REST paradigm, because of all the overhead and the twisted plumbing to manage HTTP requests.</p> <p>The early documentation about MVC4 Web Api sounds promisisng, and claims to have thinner footprint, but the more I play with it and the more I realize it has a fairly large overhead and foot print compared to WCF.</p> 2012-05-02T14:12:52-04:004962852http://forums.asp.net/p/1798985/4962852.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p></p> <blockquote><span class="icon-blockquote"></span> <h4>aliostad</h4> <p></p> <p>return new HttpResponseMessage&lt;string&gt;(null, HttpStatusCode.Conflict, <br> GlobalConfiguration.Configuration.Formatters.Where(x=&gt;x.SupportedMediaTypes.Any(y=&gt;y.MediaType == &quot;application/json&quot;)));</p> <p></p> </blockquote> <p></p> <p>Generic HttpRequestMessage and HttpResponseMessage are going away. See the latest bits:&nbsp;<a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx">http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx</a></p> 2012-05-03T03:38:52-04:005016431http://forums.asp.net/p/1798985/5016431.aspx/1?Re+HttpResponseMessage+HttpStatusCode+Conflict+returns+a+web+pageRe: HttpResponseMessage(HttpStatusCode.Conflict); returns a web page <p>Solved in VS 2012 RC. Great!</p> 2012-06-07T19:46:31-04:00