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 |
What is variable and constant in .net programming language?
Name the validation control available in asp.net ?
A brief difference between Session and Cookies in asp.net
Explain < @OutputCache% > and the usage of VaryByParam, VaryByHeader ?
What are assemblies and namespaces and explain the difference between them ?
Suggest 3 best practices in detail for for Developing High Performance Web and Enterprise Applications
When Garbage Collector will run and how its identifing whether the Object is used or Not.?
What is the use of HttpHandlers? When to use this?
What is smpte vc-1?
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?
What is difference between session and cookie?
What is versioning in .NET?
1 Answers Syntax Softtech, Wipro,
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)