Tool:Visual Studio 2015 Enterprise
OS:Windows 10、IIS 10 Express
.NET Framework 4.6、ASP.NET WebForms
在Webform之中撰寫Page_Error錯誤處理程式時,習慣使用Server.Transfer導向錯誤頁面。
例如:
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
string age = "20a";
int intArge = int.Parse(age);
}
protected void Page_Error(object sender, EventArgs e) {
Server.ClearError();
Server.Transfer("ErrorInfo.html");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
不過,在IIS 10 Express+ASP.NET WebForms 4.6的情況下,會出現錯誤,得到一個ERR_CONNECTION_REFUSED錯誤
要解決這個問題,需改用Server.TransferRequest方法,改寫程式如下
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
string age = "20a";
int intArge = int.Parse(age);
}
protected void Page_Error(object sender, EventArgs e) {
Server.ClearError();
Server.TransferRequest("ErrorInfo.html");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
沒有留言:
張貼留言