Normally I'd return HttpNotFound()
but my method returns a FileStreamResult
and I get
Cannot implicitly convert type 'System.Web.Mvc.HttpNotFoundResult' to 'System.Web.Mvc.FileStreamResult'
When I try to build. Is there an alternative version for file results?
To do this, type http://localhost:6440/welcome in the address bar of your browser while the application is in execution. When the ASP.NET Core MVC engine fails to locate the resource for the specified URL, a 404 error will be returned and you will be presented with the following error page.
How to return 404 status code from a MVC application. First way is to instantiate HttpNotFoundResult class and return the object. Next alternative is to makes use of HttpNotFound() helper method of the Controller class which returns the HttpNotFoundResult instance.
Type your action method to return the base ActionResult rather than the specific FileStreamResult. Then you can return whatever you want.
You could throw an HttpException.
throw new HttpException(404, "Not found");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With