Answered by:
How can I redirect router to 404 page?

Question
-
User1052024640 posted
I use the asp.net core MVC and redirect the page to an HTML suffix like this:
[Route("al.html")]
public IActionResult allen()
{
return View();
}When I input the URL http://localhost:5009/al.html and it works.
Now if I access the URL which is inexistent such as http://localhost:5009/all.html
The browser only shows the following text:
{"code":"40310014","msg":"invalid Referer header"}
Well, now I want it not to show the text above but redirect to the 404page.
How can I achieve this? Thank you.
Wednesday, August 7, 2019 7:44 AM
Answers
-
User711641945 posted
Hi mywatermelon,
I use Route attribute and it could show 404Page as expected if i use the wrong url. Did you configure any other thing?The error code you shown seems to be one of the CDN default error code.Please share a simple demo that could reproduce your issue and it would be more helpful.
Best Regards,
Rena
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 8, 2019 6:56 AM
All replies
-
User-1038772411 posted
Hi, mywatermelon
please add map route in your routeconfig file :
routes.MapRoute( "404-PageNotFound", "{*url}", new { controller = "StaticContent", action = "PageNotFound" } );
Reference link :
https://stackoverflow.com/questions/553922/routing-for-custom-asp-net-mvc-404-error-page
Thanks.
Wednesday, August 7, 2019 10:37 AM -
User711641945 posted
Hi mywatermelon,
I use Route attribute and it could show 404Page as expected if i use the wrong url. Did you configure any other thing?The error code you shown seems to be one of the CDN default error code.Please share a simple demo that could reproduce your issue and it would be more helpful.
Best Regards,
Rena
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 8, 2019 6:56 AM -
User1052024640 posted
Yes, I used a third-party CDN yet. I used a 404-page exception in .net core and it only works in someplace but not the HTML suffix.
I always thought it is the problem of .net core and now after I asked more about the CDN supplier, it is not the problem of .net core but the CDN.
Thanks for reminding me. Thank you.
Thursday, August 8, 2019 7:18 AM