Tell me the code snippet to show how we can return 404 errors from HttpError?



Tell me the code snippet to show how we can return 404 errors from HttpError?..

Answer / Amit Kumar Anand

To return a 404 error using HttpError, you should throw an exception of type `HttpResponseException` in your controller method.nn```csharpnpublic IHttpActionResult Get(int id) {n if (!ModelState.IsValid)n return BadRequest(ModelState);n // Your code to get the resource with given IDn if (resource == null) {n throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Resource not found"));n }n return Ok(resource);n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More ASP.NET Interview Questions

What is variable and constant in .net programming language?

1 Answers  


Name the validation control available in asp.net ?

1 Answers  


A brief difference between Session and Cookies in asp.net

5 Answers   HCL, HCL Comnet,


Explain < @OutputCache% > and the usage of VaryByParam, VaryByHeader ?

1 Answers  


What are assemblies and namespaces and explain the difference between them ?

1 Answers  


Suggest 3 best practices in detail for for Developing High Performance Web and Enterprise Applications

2 Answers   Techno Solutions,


When Garbage Collector will run and how its identifing whether the Object is used or Not.?

2 Answers   Verizon,


What is the use of HttpHandlers? When to use this?

1 Answers   Wipro,


What is smpte vc-1?

1 Answers  


To display data in the combo box, prior to setting the Data Source, what kind of property on a Combo Box do you set with a column name?

1 Answers   Siebel,


What is difference between session and cookie?

1 Answers  


What is versioning in .NET?

1 Answers   Syntax Softtech, Wipro,


Categories