开发者

My custom error message is getting overwritten

So I have a web page written in C# for ASP.NET and in some cases it returns a custom error.

For example, at one point it can be like:

Response.StatusCode = 400;
Response.Status = "A long custom error message here.";
Response.Write(Resonse.Status);

and when I open this up locally (through http://mymachinename/foo/bar.aspx)开发者_开发知识库 I see my custom error message. When I deploy it to a remote server I just see my custom error message overwritten with the text "Bad Request" (that's all). It must be some configuration, but I can't find it.


Check to see if you have the httpErrors attribute defined in your web.config.

<system.webServer>
  <httpErrors existingResponse="PassThrough" />
</system.webServer>


Servers can have their own configuration files with error codes like you mentioned. For example, editing the .htaccess file on an apache server will allow you to link your own error pages to the exceptions, or you can just write in the markup yourself to save some time.

Update

You can also do

Response.TrySkipIisCustomErrors 

if you are using IIS that is.

Additional Info

http://blogs.iis.net/ksingla/archive/2008/02/18/what-to-expect-from-iis7-custom-error-module.aspx


Those solutions provided by other guys are perfectly valid, But I think you can control it from you IIS Manager too, if there is a defined error page with code 400, Open your IIS Manager, go to .Net Error Pages, look for error code 400 click on edit feature setting on the right panel then select Off in the opened Edit Error Page Setting window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜