Monday, 31 December 2018

How to return HttpResponseException using HttpError ?

we can use HttpResponseException to return an HttpError:

public Employee GetEmployee(int empid) { Employee emp= repository.Get(empid); if (emp== null) { var message = string.Format("Employee with id = {0} not found", empid); throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); } else { return emp; } }

No comments:

Post a Comment