404页面
web config 设置
<system.web> <customErrors mode="On" defaultRedirect="error.asp" redirectMode="ResponseRewrite"> <error statusCode="404" redirect="404.aspx" /> </customErrors> </system.web> <system.webServer> <httpErrors errorMode="Custom"> <!--有3中 Custom, DetailedLocalOnly, Detailed--> <remove statusCode="404" /> <error statusCode="404" path="/404.aspx" responseMode="ExecuteURL" /> </httpErrors> </system.webServer>
在404.aspx.cs
protected void Page_Load(object sender, EventArgs e) { Response.StatusCode = 404; }
如果是自己处理route Uri 的话
try { throw new HttpException(404, "PageNotFound"); //可以 throw to 404page } catch (Exception ex) { throw ex; }
分类:
ASP.NET
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 百万级群聊的设计实践
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)