??? ??? ????? ??????? ?? ????? ASP.NET ???????? Visual C# .NET ??????? ???????

???? ???????: 306355 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ????? ??????? ????????? ???????? Visual C# .NET ?????? ?????????? ??? ????? ??? ?????? ?? ASP.NET. ????? ASP.NET ??? ?????? ??? ?????? ???????? ?? ????????? Microsoft ????? ?????? ?????? (ASP). ?? ASP.NET ? ????? ?????? ??????? ?? ??? ??????? ?????? ?? ?????????.

??????? ??????? ?? ASP.NET

???? ASP.NET ?????? ?? ???????? ?? ??? ????? ?????? ?? ????????? ??? ?????. ?? ASP ????????? ?????? ????? "??? ??? ??????? ??????" (?? ??? ???? ???????? ?? JScript). ???? ????? ??? ??? ???? ?????? "????? ??????? ???????? ?? Microsoft" (IIS) 5.0 ??????? ?????? ASPError ?????? ???? ??? ????? ??????. ??? ???? ????? ??? ????? ?????? ?????? ???.

???? ASP.NET ??? ??????? ???? ????? ?????? ?? ????????? ??? ??????? ???? ?? ???? ??? ????? ??? ??????? ASP.NET. ???? ASP.NET ????? ?????? ??????? ???? ???? ?????? ?????????? ??? ????? ??? ??????: Page_Error ? Application_Error ??? ????? ??????? (Web.config).

???? ??? ??????? ????? ??????? ??? ??????? ??????? ?? ASP.NET ????? ?? ???????. ??? ????? ?? ?? ???? ??? ??????? ????? ????? ????? ??? ????? ??????? ?? ??????? ?????? ????? ????? ?????? ??? ASP.NET ? ?? ???? ??? ?????? ?????? ????? ??? ???? ???????? - catch-??????? ????? ??????? ??? ????? ????? ?????? (CLR) ??????? ??????.

????? ??????? ??????? Page_Error

???? ????? ??????? Page_Error ????? ??? ?????? ??????? ???? ???? ????? ??????. ????? ??? ??????? ????? ?????? (??? ???? ????? ???????? ???????? ???????) ? ?? ????? ????? ????? ?? ????? ????? ???.

?????? ???? ??? ?????? ??????? ????? ??????? ?? ???????? ??? ?????? ????? ????????. ?????? ??? ???? ????? ??? ??? ??????? ????? ??? ???????? ??????? ???????? ???? ??? ????? ??????? ??? ????????. ????? ????? ????? ???? ???? ????? ??? ???????? ??????? ??? ??? ??? ?? ????? ?????? ????? ??????? ?????? ?? ??? ???????.

???? ??? ?????? ??????? ????? ???? ??? ?? ????? ??????? Page_Load. ???? ??????? ??????? ?????? ?????? ??????? ???? ??? ???????? ????? ??????? Page_Error.
  1. ???? ??????? ??????? ?????? ??? ???? ???? PageEvent.aspx ??? ???????:
    1. ???? Microsoft Visual Studio .NET.
    2. ?? "?????? ??????" ???? ??? ?????? ?????? ??? ???? ??????? ??? ??? ????? ?? ?? ???? ??? ????? ????? ???.
    3. ?? ???? ???? ??? ???? PageEvent.aspx ??? ?? ???? ??? ???.
  2. ????? ???????? ???????? ??????? ??? PageEvent.aspx:
    <script language=C# runat="server">
    void Page_Load(object sender, System.EventArgs e)
    {
    	throw(new ArgumentNullException());
    }
    
    public void Page_Error(object sender,EventArgs e)
    {
    	Exception objErr = Server.GetLastError().GetBaseException();
    	string err =	"<b>Error Caught in Page_Error event</b><hr><br>" + 
    			"<br><b>Error in: </b>" + Request.Url.ToString() +
    			"<br><b>Error Message: </b>" + objErr.Message.ToString()+
    			"<br><b>Stack Trace:</b><br>" + 
    	                  objErr.StackTrace.ToString();
    	Response.Write(err.ToString());
    	Server.ClearError();
    }
    </script> 
    					

    ?????? ?? ??? ?????? ??? ??? AutoEventWireup ?? ??? ????? ?????. ??? ??? ??? ????? ????? ???? ??? ????? AutoEventWireup, ??? ??????? ?? ?????????? ???? ?????. ??? ??? ?????? Visual Studio .NET "?????? ?????????, ??? ????" ????? ??? "???? ???? ?????? ???? ????? AutoEventWireup ??? false. ???? ?????? ??? ??? ?????? ?????????? ???? ???????? ASP.NET ? ?????? ?????????? ?????? ????????? ???????? ???? Visual Studio .NET ??? ?????. ??? ?? ????? ???? ????? AutoEventWireup ??? false "? ?? ????? ??????? ??????? ???? ?? ??????? ?? ???? .ASPX. ?? ???? ?????? ??? ?? ??? ???? ??? ??? ???????.
  3. ?? ??????? ???? ???? ??? ??? PageEvent.aspx.
  4. ???? ??? ?????? ?????? ??? ?????? ?? ???? ??? ??? ?? ?????? ?????? ??????. ???? ?? ????? ??? ?????? ????? ???????? ??? ??????? ????????? ????????.
?????? ?? ????? ?? ???????? ???????? ?????? ??????? Server.ClearError. ???? ??? ????? ?? ???????? ??? ????? ??????? Application_Error.

???????? ??? ???? ????? ????? ????? ?????? ????? Inherits ?? ????? ?????? @. ??? ?? ????? Inherits ??? ????? ??????? ??? ?????? ??? ??????. ?? ????? ??????? ????? ? ???? ????? ????? ???????:
'Project.PageEvent' ??? ??? ????

????? ??????? ??????? Application_Error

???? ????? ??????? Page_Error ????? ??????? ????? ????? Application_Error ??? ?????? ??????? ???? ???? ?? ??????? ????? ??. ????? ????? ??????? ???? ??????? ???? ????? ??????? ????? ??????? ?? ?????? ??????? ????? ????????? ?????? ???? ?? ????.

????? ??????? ???????? ??? ????? ????????? ???????? Page_Error ?????? ?? ???? ?????? ??? ?? ?? trapped ????? ?? Page_Load ?? ????? ??????? Page_Error. ??? ????? ????? ??????? Application_Error ?? ??? Global.asax ??????? ????? ??. ??????, ??????? ?? ??? ?????? ?????? ???? ????? ?? ??? ????????? ?????? ????? ?? ????? ??????? Application_Error ??? Global.asax ?? ????? ????? ??? ??? ???????. ???? ??????? ??????? ????? ??????? ??????? Application_Error:
  1. ????? ??? ???? ???? AppEvent.aspx ??? ???????.
  2. ?? ?????? ????????? ???????? ??????? ??? AppEvent.aspx:
    <script language=C# runat="server">
    	void Page_Load(object sender, System.EventArgs e)
    	{
    		throw(new ArgumentNullException());
    	}
    </script>
    					

    ?????? ????? ????????? ??? ???????? ?? ?????? "Page_Error" ??? ??? AutoEventWireup ????? ??? ????? ????????? ???????? ?? ??? ??????. ???? ????????? ??????? ?? ????? "Page_Error" ?????? ??? ???? ?? ????????.
  3. ?? ??????? ???? ???? ??? ??? AppEvent.aspx.
  4. ????? ????? ????? Application_Error ??? ??? Global.asax ??? ?????? ??? ??????? ?? ????? ??????? Page_Load ?????? AppEvent.aspx. ???? ??? ??? ????? ????? ???????? ??? ?????? ????? System.Diagnostics Global.asax ???????? ??? ???????.

    ?? ?????? ????????? ???????? ??????? ??? ??? Global.asax:
    using System.Diagnostics;
    
    protected void Application_Error(object sender, EventArgs e)
    {
    	Exception objErr = Server.GetLastError().GetBaseException();
    	string err =	"Error Caught in Application_Error event\n" +
    			"Error in: " + Request.Url.ToString() +
    			"\nError Message:" + objErr.Message.ToString()+ 
    			"\nStack Trace:" + objErr.StackTrace.ToString();
    	EventLog.WriteEntry("Sample_WebApp",err,EventLogEntryType.Error);
    	Server.ClearError();
    	//additional actions...
    } 
    					
  5. ??? ????? Global.asax.
  6. ?? Visual Studio .NET ? ?? ??????? ????? ? ???? ??? ?????.
  7. ???? ??? ?????? ?????? ??? ?????? ?? ???? ??? ??? ?? ??????. ?? ??? ?????? ???? ?????? ?????, ??? ????? ?? ???? ??? ?? ????? ????? ????? ???? ?? ??? ???????. ???? ??? ??????? ????? ?? ??? ??????? ???? ???? ?????? ????? ?? "???? ???????". ??? ????? ????? ?? ????? ??? ????? ????? ???????? ??? ???? ??? ??????? ??????? ???????? ?????? ???? ???? ?? ???? ??? ????????? ?????? ??? ??????.

????? ??????? ??? Web.config

??? ??? ??????? Server.ClearError ?? ?????? ???????? ????? ?? Page_Error ?? ????? ????? Application_Error ? ????? ???????? ??? ????????? ???????? ?? ?????? <customerrors>??? Web.config. ?? ?????? <customerrors>????? ????? ???? ????? ????? ?? (???? "??? ?????????defaultRedirect) ?? ??? ???? ????? ???????? ??? ??? ??? HTTP ???? ????. ????? ??????? ??? ??????? ?????? ????? ????? ???? ??????? ????????.

?? ???? ???? ???? ?? ??? trapped ?? ?? ?? ????????? ??????? ?? ??????? ????? ?? ??? ??? ??? ?????? ?????. ???? ??? ????? ????? ????? ??? Global.asax ???? ?? ??? ??????? Server.ClearError. ????? ????? ??? ?????? ????? ?? ??? Web.config ????? ?????? ??? ?????? ?????.
  1. ??? ??? Global.asax ?? ?????? ??????.
  2. ????? ?????? ??? Server.ClearError ????? surfaces ????? ?? Web.config ?????.
  3. ??? ????????? ??? Global.asax. ??? ?? ???? ???????? ???????? ?????? ?? ???? ?????? ??? ???:
    using System.Diagnostics;
    
    protected void Application_Error(object sender, EventArgs e)
    {
    	Exception objErr = Server.GetLastError().GetBaseException();
    	string err =	"Error Caught in Application_Error event\n" +
    			"Error in: " + Request.Url.ToString() +
    			"\nError Message:" + objErr.Message.ToString() + 
    			"\nStack Trace:" + objErr.StackTrace.ToString();
    	EventLog.WriteEntry("Sample_WebApp",err,EventLogEntryType.Error);
    	//Server.ClearError();
    	//additional actions...
    } 
    					
  4. ?? ?????? ???????? ???????? ??????? ??? ?????? <customerrors>?????? ????? ???????? ??? ???? ?????:
    <customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
    </customErrors>
    						
    ?????? ??? ?? ????? ????? ???? ????? ?? ????? "defaultRedirect ???? ???? ???? ??? ??? ????? ???? ???????.
  5. ???? ??? ????? ????? trapped ?? ??? ??????? ??? ???? ??????? ???????? ? ??? ?? ???? ?????? ???? ??? ???? ErrorStatus.htm. ?? ?? ???????? ??????? ??? ??????? ?????? ?? ??? ????? ????????? ???? ?????? ??? ?????? ??? ???? .htm ???? ?????. ?? ?????? ????????? ???????? ??????? ??? ErrorStatus.htm:
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
    </HEAD>
    <BODY>
         <b>Custom Error page!</b>
         <br>
         You have been redirected here from the <customErrors> section of the 
         Web.config file.
    </BODY>
    </HTML>
    					
  6. ??????? ???????? ???????? ??? ??????? ????? ??????? ?? ?? ???? AppEvent.aspx ?? ????????. ???? ??? ??? ??? ?????, ??? ????? ?????? ??? ???? ErrorStatus.htm.
??? ????? ?? ??? ????? ?????? ??? ???? ??????? ???????? ?? ???? ????? "defaultRedirect" ?? ?????? <customerrors>? ????? ????? ????? ???? ????? ?????? ????? ??? ???????? ??? ??? ??? HTTP ???? ????. ???? ???? <error>???? ??? ??????. ??? ???? ??????:
<customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
	<error statusCode="404" redirect="filenotfound.htm" />
</customErrors>
				
?????? ?????? ?????? ?? defaultRedirect ?????? <customerrors>??? .htm. I

????? ????? ?????? <customerrors>??? ??? ????? ??? ?????. ??? ??????? ????? ??? ?????? ?? ????? ???? ????? ??????? ???. ??? ???? ??????? ??? ??? ???? ?????? ??????? ???? ?? ??????? ?????? ????? ????? ASP.NET ?????? ?? ?? ???? ?? ??? ????? ?????? ??? ???? ????? ??????? ??????? ???????? ?????? ????. ????? ??? ??? ????????? ???????:
  • ???: ??????????? ??? ???????? ????? ???????? ??? ?????? ??????? defaultRedirect. ??? ??????? ??? ????? ???? ????? ?? ???????.
  • ?????: ???? ??????? ??????? ??????????? ?? ??? ????? ?????? ??? ???? defaultRedirect. ??? ??????? ??? ????? ???? ????? ?? ?????.
  • RemoteOnly: ??? ????? ?????????? ????? ?????? ??????? ??? ?????? ??????? ??? ????????? ?????? (???????? localhost) ??????? ???????. ??? ????? ????? ???? ?????????? ??????? ??? ?????? "defaultRedirect". ??? ??????? ??? ????? ???? ????? ?? ??? ???????.

??????? ??????? ????????

?? ????? ?? ??????? ????????? ?? ???? ??????? Microsoft Windows 2000 ??? Microsoft Windows XP ? ASP.NET ??? ????? ????????? ???????? ??????? ??? ?? ????? ????. ???? ??? ??????? ?????????? ???? ???? unprivileged ???? ???? ASPNET. ?? ??????? ???? ?? ASP.NET ? ??? ???? ????? ?????? ???? ?????? ???? ????????? ?????? ?? ??????.

?? ??????? ????????? ????? ?? ??? Windows Server 2003 (IIS 6) ? ASP.NET ????? ????????? ???????? ??????? ??? ?? ????? ????. ???? ??? ??????? ?????????? ???? ????? ???? NetworkService.

?????? ??? ???? ?? ????????? ??? ??? ??????? ????? ???? ???? ??????? ?????? ????????? ???????? ?? ??? ??????? ?????? ???????? ?????? ???? ?? ??????? ???? ???? ?????? ?????? ????? ????? ???????:
??????? ??????? ?????? 1 ?? Microsoft .NET Framework
http://msdn2.microsoft.com/en-us/library/ms994923.aspx

?????

????? ?? ?????????? ?? ?????? ????? Microsoft ??????? ??? ?????:
????? ????????? ?? .NET
http://msdn2.microsoft.com/en-us/library/ms954599.aspx????? HttpServerUtility.ClearError
http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility.clearerror(vs.71).aspx???? ????? .NET MSDN
http://msdn2.microsoft.com/en-us/netframework/default.aspx?????? ???????? Microsoft .NET
http://www.microsoft.com/net/

???????

???? ???????: 306355 - ????? ??? ??????: 15/?????/1428 - ??????: 4.8
????? ???
  • Microsoft ASP.NET 1.0
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft ASP.NET 1.1
  • Microsoft Visual C# .NET 2003 Standard Edition
????? ??????: 
kbmt kbconfig kbhowtomaster kbweb KB306355 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????306355

????? ???????