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

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

?? ??? ??????

??????

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

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

???? ASP.NET ?????? ?? ???????? ?? ????? ?????? ?????????? ??? ???????. ?? ASP ?????????? ????? ??????? ?? ????? "On Error Resume Next" (?? ??? ???? ???????? ?? JScript). ????? ?? ???? ??? ??? ?????? Microsoft Internet ??????? Services (IIS) 5.0? ????? ??????? ???? ASPError ?????? ???? ??? ???? ??????. ??? ???? ??? ????? ?? ??????.

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

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

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

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

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

???? ??? ?????? ??????? ?????? ??? ???? ??? ?? ????? ??? Page_Load . ???? ??? ??????? ?????? ?????? ?????? ???? ???? ??????? ????? ????? Page_Error .
  1. ???? ??? ??????? ?????? ??? ???? ???? PageEvent.aspxto ??????? ????? ??:
    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 ? ?????? ?? ????????? ?????? true . ??? ??? ?????? Visual Studio.NET ?????? ????????????? ???? ????????? ???????? ???? "????? ???" ????? ???? ????? AutoEventWireup ??? false. ???? ?????? ??? ??? ??????????? thatASP.NET ?????? ??????????? ??????? ?????????? ???? ????????? ???? Visual Studio.NET ???? ?????. ??? ?? ????? ???? ????? AutoEventWireup ??? false? ??????? ??????? ???? ?? ??????? ??.??????? ?? ???? ASPX. ?? ???? ?????? ??? ?? ??? ???? ??? ????????????????.
  3. ?? ??????? ??? ? ???? ??? ??? PageEvent.aspx.
  4. ?? ?????? ?????? ??? ?????? ??? ?? ???? ??? ??? ?? ?????? ?????? ??????. ???? ??? ??? ??? ????? ?????????????????? ???????? ????????? ????????.
?????? ?? ????? ?? ???? ????????? ???????? ??????? Server.ClearError. ???? ??? ????? ?? ????????? ?? ????? ????? Application_Error .

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

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

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

???????? ??? ????? ????????? ???????? ?????? Page_Error ??????? ????? ?????? ??? ?? ??? ??????? ?? 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. ???? ??? ??? ???????? ??????? ????? ?? ????? ??????? ? Global.asax ???????? ??? ???????.

    ????? ??????? ?????? thefollowing ??? ??? 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 ?? ?????? ???????? ????? ?? ????? ??????? Application_Error ?? Page_Error ? ????? ???????? ??? ????????? ???????? ?? ?????? <customErrors>?? ??? Web.config. ?? ?????? " <customErrors>"? ????? ????? ???? ????? ????? ????? ????? ???????? (defaultRedirect) ?? ????? ????? ????? ???????? ??? ??? ??? HTTP ???? ??? ???????. ????? ??????? ??? ??????? ?????? ????? ????? ???? ??????? ????????.

??? ??? ??? ???? ?? ??? ????? ?? ?? ????? ?? ????????? ??????? ?? ??????? ????? ??? ??? ??? ??? ?????? ?????. ???? ??? ????? ????? ????? ??? Global.asax ???? ?? ??? ??????? Server.ClearError . ??????? ????? ??? ?????? ????? ?? ??? Web.config ???? ???? ???? ?????. </customErrors></customErrors>
  1. ??? ??? Global.asax ?? ???????????????.
  2. ?? Server.ClearError ?????? ?? ?? ???? ??? ?? Web.configfile ???????.
  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>????????? ?????? ????? ???????? ??? ???? ?????:<b00> </b00> </customErrors>
    <customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
    </customErrors>
    						
    ?????? ??? ????? ???? ????? ?? ????? defaultRedirect ??? ???? ???? ??????? ??????????? ???? ??? ??? ?????.
  5. ????? ??????? ???? ??? ????? ?? ??? ??????? ????? ???? ????? ????????? ??? ???? ????? ???? ??? ??????? ErrorStatus.htm.Keep ?? ???????? ?? ??? ??????? ??? ??????? ?????? ?? ?? ???? ??? ?????? ??? ?????? ??? ?????? ????.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>???? ??????. ??? ???? ??????:<b00> </b00> </error> </customErrors>
<customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
	<error statusCode="404" redirect="filenotfound.htm" />
</customErrors>
				
?????? ?????? ?????? ?? defaultRedirect ??? <customErrors>????? ?? ???.htm. ???

???? ?? ??? ?????? <customErrors>????? ??? ????? ???? ?? ?????? ??? ?????. ??????? ??? ????? ?????? ?? ????? ???? ??? ????? ???????. ??? ???? ??????? ??? ??? ???? ?????? ???????? ????? ?????? ???? ?????? ????? ??? ASP.NET ?????? ??? ???? ?? ??? ????? ?????? ??? ???? ??? ???? ???? ????????. ????? ??? ??? ????????? ???????: </customErrors></customErrors>
  • ???: ??????????? ??? ???????? ?????? ????? ???????? ??? ?????? ??????? defaultRedirect . ??? ??????? ??? ????? ????? ?? ???????.
  • ?????: ???? ??????? ??????? ?????????? ??? ??? ???????????? ???? defaultRedirect . ??? ??????? ??? ????? ????? ?? ???????.
  • ??????????: ??? ?????????? ????? ?????? ??? ???? ??? ????????? ?????? (???????????????) ???? ??????? ?????????. ??? ????? ????? ???? ?????????? ??? ???? defaultRedirect . ??? ??????? ??? ????? ????? ?????? ???????.

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

?? ??????? ????????? ????? ?? ??? ???? ??????? Microsoft Windows 2000 ????? ??????? Windows XP? ASP.NET ????? ????????? ???????? ??????? ??? ?? ????? ????. ???? ??? ??????? ?????????? ????? ???? ????? ??? ????? ???????? ???? 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

????? HttpServerUtility.ClearError

???? ?????.NET MSDN

?????? ???????? ? Microsoft.NET

???????

???? ???????: 306355 - ????? ??? ??????: 23/?? ?????/1434 - ??????: 1.0
????? ???
  • Microsoft ASP.NET 1.0
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft ASP.NET 1.1
  • Microsoft Visual C# .NET 2003 Standard Edition
????? ??????: 
kbconfig kbhowtomaster kbweb kbmt KB306355 KbMtar
????? ????
???: ??? ????? ??? ??????? ???????? ????? ?????????? ??????? ?????? ??? ??????? ?? ??? ??????? ?? ??????? ??? ??? ?? ???? ????????? ???? ??????? ???????(CTF) ?? ?? ???? ????? ????. ???? ?? ???? ?????????? ??? ???????? ???????? ???? ??? ?? ???????? ??????? ?? ??? ??????? ???????? ?? ??? ??????? ??????? ??? ?????? ?? ?????? ??? ???? ???????? ???????? ?? ????? ??????? ????? ????? ??????. ??? ?? ???????? ???????? ?? ????? ??? ????? ?? ???????? ?? ???? ????? ?? ?????. ?????? ??? ???? ?????????? ???? ?????? ?? ??? ????? ?? ??? ??? ?? ??????? ?? ??? ????? ?? ???? ????? ????? ?? ????? ??????? ???? ?? ???????? ?? ??? ???????.
???? ??? ????? ??????? ?????? ??????????306355

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

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com