Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:45:39+00:00 2026-06-02T23:45:39+00:00

I am trying to return an HTTP Status Code of 201 Created for a

  • 0

I am trying to return an HTTP Status Code of 201 Created for a RESTful POST operation using ASP.NET 4 Web API, but I always get a 200 OK.

I’m currently debugging on IIS 7.5.7600.16385, VS 2010 Professional, Windows 7 64-bit Professional.

public MyResource Post(MyResource myResource)
{
    MyResource createdResource;
    ...
    HttpResponse response = HttpContext.Current.Response;
    response.ClearHeaders(); // added this later, no luck
    response.ClearContent(); // added this later, no luck
    response.StatusCode = (int)HttpStatusCode.Created;
    SetCrossOriginHeaders(response);
    return createdResource;
}

I have seen other examples where HttpContext.Current.Response.StatusCode is set before returning data, so I didn’t think this would be a problem. I haven’t tracked it down in the MVC 4 source yet.

(This is related to my investigations with this question but different enough topic to warrant its own question)

I am not sure whether the problem is IIS or the Web API. I will do further tests to narrow it down.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:45:41+00:00Added an answer on June 2, 2026 at 11:45 pm

    HttpContext.Current is a hangover from the past.

    You need to define response as HttpResponseMessage<T>:

    public HttpResponseMessage<MyResource> Post(MyResource myResource)
    {
        .... // set the myResource
        return new HttpResponseMessage<MyResource>(myResource)
                {
                    StatusCode = HttpStatusCode.Created
                };
    }
    

    UPDATE

    As you might notice from the comments, this approach works with beta release. Not the RC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set a custom HTTP 1.0 status code in order to return
I'm trying to use the geocoding code from here in my ASP.NET MVC 2
I am trying HTTP Post an XML string to a WebMethods server using basic
Trying to follow someone on Twitter using new iOS 5 API, getting 406 return
I'm trying to return a ContentPart from the HTTP session in a Driver. Here
I'm trying to code a tooltip, which uses http://craigsworks.com/projects/simpletip/# simpletip plugin, which returns data
i'm trying to return a custome object from a web service object returned only
I'm trying to return a 200 status with an empty body but rails returns
I need to perform asp.net web-service function call via jQuery and pass asp.net application
I am trying to authenticate to a server's secure URL using java.net.urlconnection - based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.