1

I'm using the basic Response.StatusCode to set the status code to 9999. This page is being called via an AJAX call, checking the status code on readyState = 4 and popping an alert on 9999 using the message set by Response.StatusDescription. All I'm getting is readyState = 4 and statusCode = 200. I can provide code if needed, but it's not trim, so I'll trim it down if the code is needed/requested. Any help is appreciated.Coded in C# ASP.NET and Javascript.

UPDATE Purpose: I'm suing the status code 9999 to denote a "User already exists" error when adding a user to an SQL table. This is the only way I can find to let the AJAX call know when this error occurs.

7
  • 1
    Sorry, I'm a bit confused - which numbers are C# and which JavaScript? You're sending 9999 from C# and seeing 200 in the JavaScript? Commented May 15, 2012 at 15:59
  • 3
    Why are you trying to override the HTTP status codes? They do have meaning you know. Commented May 15, 2012 at 16:00
  • @Rup Yes I'm sending 9999 from C# and getting 200 in JavaScript Commented May 15, 2012 at 16:01
  • 1
    You couldn't add an ErrorMessage field to your JSON instead? Commented May 15, 2012 at 16:05
  • 1
    Maybe you're looking for 409 Conflict? w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10 Commented May 15, 2012 at 16:07

1 Answer 1

8

You can't make up status codes. Here are the valid ones

I think the best option is to send back your status and message in a json response.

{
    status: 9999,
    message: "User already exists"
}

Here is a SO post with some links that might educate you on how to do this: Returning JSON object from an ASP.NET page

Sign up to request clarification or add additional context in comments.

3 Comments

I've never dealt with json before. I've added the purpose of my attempt above. Would json work for this and do you have a link to a good json tutorial or something i could educate myself with?
@steventnorris Sure thing! I've added a link that should help you out.
Ended up using a 409 status code for my purposes (path of least resistance), but I looked at the JSON and it's pretty neat. Would have worked just as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.