Note that there are some explanatory texts on larger screens.

plurals
  1. POIIS Overwriting HTTP Response Text When HTTP Response Status set as 400
    primarykey
    data
    text
    <p>I am building an MVC 3 application with an IIS 7.5 backend. On my controller, I have action methods that allow the user to add/edit domain objects. The Action handles HTTP Post, has a return value of string which contains any validation error messages encountered during the save process. Here is an example of one Action Method:</p> <pre><code> [HttpPost] public string CustomerEdit(CustomerModel customerModel) { var errorMessages = new StringBuilder(); var serverErrors = new List&lt;string&gt;(); //Map to a customer domain object Mapper.CreateMap&lt;CustomerModel, Customer&gt;(); var customer = Mapper.Map&lt;CustomerModel, Customer&gt;(customerModel); if (customerModel.Oper == "del") { var customerIds = new List&lt;Guid&gt;(); customerIds.Add(customer.Id); if (!_serverService.DeleteCustomers(customerIds)) { errorMessages.Append("The item could not be deleted"); Response.StatusCode = Constants.STATUS_SERVER_ERROR; } } else { //Validate if (!_serverService.ValidateCustomer(customer, out serverErrors)) { foreach (var error in serverErrors) { ModelState.AddModelError("Validation", error); } } //Save if (ModelState.IsValid) { var saveStatus = _serverService.SaveCustomer(ref customer, _id); if (!saveStatus) { errorMessages.Append("The server encountered and error during Save"); Response.StatusCode = Constants.STATUS_SERVER_ERROR; } } else { errorMessages.Append(GetValidationErrors(ModelState)); Response.StatusCode = Constants.STATUS_SERVER_ERROR; } } return errorMessages.ToString(); } </code></pre> <p>In the case of an error, I need to set the Response.StatusCode property to a value of either 400/500, and return a concatenated string of detailed error messages. Unfortunately, IIS always strips my error string out of the response test, and (in the case of 400 errors) adds replaces it with the string 'Bad Request'</p> <p>Is there a way to configure IIS to return a custom, Action-specific, string when the status code is set to 400?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload