Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC - HTTP Status Codes (i.e. 303, 401, 404, etc)

In ASP.Net MVC is it possible to use either Redirect or RedirectToAction to call for example a 303 error?

I am working my way through a book titled "ASP.NET MVC 1.0 Website Programming" and the source is making calls such as return this.Redirect(303, FormsAuthentication.DefaultUrl); but this call only functions with an external library, I would like to have the same functionality sans the add-on if possible.

like image 994
mynameiscoffey Avatar asked Dec 30 '09 06:12

mynameiscoffey


People also ask

What are status code 2xx 3xx 4xx 5xx in API?

2xx successful – the request was successfully received, understood, and accepted. 3xx redirection – further action needs to be taken in order to complete the request. 4xx client error – the request contains bad syntax or cannot be fulfilled. 5xx server error – the server failed to fulfil an apparently valid request.

What is a 200 status code?

The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default. The meaning of a success depends on the HTTP request method: GET : The resource has been fetched and is transmitted in the message body.

What is OkObjectResult?

OkObjectResult. An ObjectResult, when executed, performs content negotiation, formats the entity body, and will produce a Status200OK response if negotiation and formatting succeed. public OkObjectResult OkObjectResult() { return new OkObjectResult(new { Message="Hello World !" }); } C#

What are HTTP response status codes?

HTTP response status codes (or simply status codes) are three-digit codes issued by a server in response to a browser-side request from a client. These status codes serve as a means of quick and concise communication on how the server worked on and responded to the client's request.


1 Answers

You can create custom ActionResults that mimic any http response code you'd like. By returning those action results, you can easily perform a 303.

I found this quick write-up that you should be able to follow easily.

like image 178
womp Avatar answered Sep 18 '22 23:09

womp