简体   繁体   English

自定义404错误消息ASP.NET Visual Studio

[英]Custom 404 Error Messages ASP.NET Visual Studio

Anyone know how to set the custom 404 Error pages that the Visual Studio Development Server uses? 任何人都知道如何设置Visual Studio开发服务器使用的自定义404错误页面?

I know how to get it to work if I set is as a local IIS server and then setup the custom 404 pages in IIS. 如果我将其设置为本地IIS服务器,然后在IIS中设置自定义404页面,我知道如何使其工作。 But I want to actually change them on the local VS development server so that when I test the application in Visual studio's Development server, it just works. 但我想在本地VS开发服务器上实际更改它们,这样当我在Visual Studio的开发服务器中测试应用程序时,它才能正常工作。

I'm assuming its a setting in VS. 我假设它在VS中的设置。

I'm currently running VS 2010. 我目前正在运行VS 2010。

I've already added the custom 404 redirect for .aspx pages in the web.config. 我已经在web.config中为.aspx页面添加了自定义404重定向。 Now I need to figure out to change the error redirect for all other pages. 现在我需要弄清楚更改所有其他页面的错误重定向。

Not sure if this is what you are after, but you can set it up in your web.config as follows: 不确定这是否是您所追求的,但您可以在web.config中进行设置,如下所示:

<customErrors defaultRedirect="GenericError.htm" mode="On">
          <error statusCode="404" redirect="notfound.htm"/>
      </customErrors>

and have a html file called notfound.html 并有一个名为notfound.html的html文件

References: 参考文献:

The easiest way is probably to just set up an application on your local IIS, or use that "IIS Express" option that vs 2010 provides: http://learn.iis.net/page.aspx/868/iis-express-overview/ 最简单的方法可能是在本地IIS上设置应用程序,或使用vs 2010提供的“IIS Express”选项: http//learn.iis.net/page.aspx/868/iis-express-overview /

You could also use a "mock config" approach, but this strikes me as too much work. 您也可以使用“模拟配置”方法,但这对我来说太过分了。 Testing Methods with Reference to Web.Config in .Net C# 在.Net C中引用Web.Config的测试方法#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM