????? ????? c# .NET ?? ????? ???? ASP.NET ??? ??????? ?????????? ?????? ????? ?? ??? ????

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

?? ????? ??

??????

?? ???? ????? ???? ?? ?? ????? ?? ?? ?? ASP.NET ??? ??, ?? ????????? ?? ??? ???????? ???? ?? ??? ????? c# .NET ??? ?? ????? ???? ????? ?????? ?? ???????? Microsoft ?????? ????? ????? (ASP) ???????? ??? ?????? ASP.NET ?????? ??? ??? 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 ???? ?? ??? ???? ??????? ?? ??? ??? ??????? ?????? ?????????? ?????? ???? ?? ??? ???? ?? ???? ????? ???? ??, ?????? ?? ???? ???? ??????? ???? ??????-???-????? ????? ?? ??????? ???? ?????? (CLR) ????? ?????? ?? ???????? ??? ?????? ?? ????? ?????

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

Page_Error ????? ?????? ????? ???? ?? ??????? ???? ???? ????????? ?? ????? ???? ?? ?? ????? ?????? ???? ??? ?? ??? ??? ????? ??? ?? ???? ???? ?? ??? (??) ??? ?? ?? ?????? ??????? ????????? ?? ???? ???, ?? ?? ????? ??? ?? ??? ???? ?????? ????????? ?? ???? ????

??? ?? ?????? ??? ???? ???????? ?????????? ?? ??? ???????? ??????? ?????? ??????? ????????? ???? ??? ??? ?? ????????? ??????? ?? ????? ??? ?? ?? ??? ??, ?? ??? ????? ?? ?????????, ?? ???? ??? ??????? ????????? ???? ??? ?????? ???? ???? ??? ???? ???? ??? ?????? ??????? ??? ?? ?????? ????? ????, ?? ??? ?????? ??? ??????? ?????? ????? ????? ??? ??? ??? ?????????? ?? ??? ??? ????? ????????? ???? ?? ??? ?? ??????? ???? ?????? ?? ???? ???

?? ?????? ?? ?? ?????, ?? ?????? Page_Load ????? ?????? ??? ??????? ???? ?? ??? ???? ? ????, throws. ????????? ????? Page_Error ????? ?????? ?? ????? ?? ??? ?? ????? ????? ?? ???, ????? ????? ?? ???? ?????
  1. PageEvent.aspxto ???? ?? ?? ????? ???? ????????? ?? ?????? ?? ???, ????? ????? ?? ???? ????:
    1. Microsoft Visual Studio .NET ?? ??????
    2. ?????? Explorer ???, ????????? ??? ????-????? ????, ????? ???? ?? ??? ??????, ?? ???? ??? ??? ??????? ???????
    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 ??????? ?????? ??? ?? ??? ???? ??? Assigna ??? AutoEventWireup ??????? ?? ?????? ??? ?? ???? ???? ???, ?? ???????? ??? true ????? ???? ??? ?? Visual Studio .NET ?? ????? yourapplications ?????? ???? ?? ??? ?? ??? ???, ?? ??? ??????? ???????? ??? ?????? ??? ?? AutoEventWireup ??????? ??? false???? ?? ??? ??? ??? ???????? ??? thatASP.NET ????? ?? ??? ?? ?????????? ???? ??, ?? ???????? ??? ?? ??????? ?? ??? Visual Studio .NET ???????? codeassigns. ??? AutoEventWireup ??????? ??? false, ??? ????? ????? ?????? ?? ??? ??? ???? ??? ???ASPX ????? ? notfire. ?? thisfunctionality ?? ???? ??? ???? ????? ??? ?? confusing ?? ???? ???
  3. ????? ' ???? ??, PageEvent.aspx ??????????? ?????
  4. ????? ?? ????-????? ????, ?? ?? ????? ?? ????? ?? ??? ???????? ??? ????? ????? ????? ?????? ???? ??? ?? ?? ????? ?? ??? ??????????? ?? ??? reportedaccording.
??? ?? ??? ?? ??? ???? ?? ??? Server.ClearError???????? ??? ???? ???? ?? ?????? Application_Error ????? ?????? ?? ??? ??? ????? ?? ????? ???

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

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

Page_Error ????? ?????? ?? ????, ?? Application_Error ????? ?????? ???? ????????? ??? ??????? ???? ???? ????????? ?? ????? ???? ?? ??? ????? ?? ???? ???? ????? ?? ???? ?????????-???? ???????, ?? ????????? ?? ?????? ??????? ??? ?? ?? ?????????-???? ????????? ??????? ?? ???? ???? ???? ????? ?? ???? ????

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

    ??? "Page_Error" ?????? ??? ????? AutoEventWireup ??????? ?? ???? ??? ??????? ?? ?? ??? ??? ??? ????? ?? ??? ???? ??? Theinformation ??? ???? ??????? ?? ??? "Page_Error" ?????? ??????
  3. ????? ' ???? ??, AppEvent.aspx ??????????? ?????
  4. ?? youthrow ??? AppEvent.aspx ????? ?? Page_Load ????? ?????? ?????? ?? ????? ???? ?? ??? Global.asax ????? Application_Error ????? ?????? ??????? ????? ??? ?? addanother ????? ??? ?? ????? ???? ?? ??? Global.asax ?? ??? System.Diagnostics ??? ????? ?? ??? ??? ?? ????? ???? ??? ??????

    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. ????? ?? ????-????? ????, ?? ???? ??? ???????? ??? ?????????? ????? ?? ?????? ??? ????? ????? ?? ?????, ???????, ?? ?? ?? ????????? ????? ??? ??? ????? ??? ?? noticethat ?????? ?? ????? ????????? ??? ????? ?????? ?? ?????? ?? ???? ??, ??? ?? ????????? ????? ??? Loggingthe ?????? ?? ??? ?? ?????????? ???? ???? ???? ??????????-friendlyerror ????? ?? ??? ?????????????? ????, ?? ??? ?????? ??, ?? ??? ???????? ???????? ???? ?? ??? ????? ?? ???? ???

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

??? ?? Server.ClearError ?? ??? ???? ?? Page_Error ?? Application_Error ????? ?????? ??? ??????, ?????? ????? ???? ???? ?? <customErrors>?????? ?? web. config ????? ??? ???????? ?? ?????? ??? <customErrors>?????? ???, ?? ??? ???????? ?????? ????? (defaultRedirect) ?? ??? ??? ???? ???????????? ????? ????????? ?? ???? ??? ?? ??? ????? ??? ????? ?? HTTP ?????? ??? ?? ?????? ???? ?? ??? ????????? ????? ?????????? ?? ????? ???? ?????? ????? ?? ???????? ???? ?? ??? ?? ?? ???? ?? ????? ?? ???? ????

????? ???? ???? ????????? ??? ?? ???? ?? ?? trapped ???? ?? ?? ?????? ???? ??, ?? ?? ????? ????? ????????? ???? ??? ?? ?????? Server.ClearError ??? ?? ??? ???? ?? ?? Global.asax ????? ??????? ???? ?? ??? ???? ????????? ???? ?? ??? ?????, ?????? web. config ????? ??? ????? ?????? ?? ??? ????? ????? ?? ??? ??? ??????? ??? </customErrors></customErrors>
  1. Previousexample ?? Global.asax ????? ??????
  2. ?? Web.configfile ??? ?????? ????? ????????? ???? ?? ??? Server.ClearError ???? ????????
  3. ???? ?????????? ?? ?????? ?? ??? Global.asax. ???? ??? nowappear ????? ?? ???? ???? ?????:
    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>sectionto ???? ?? ??? ??? ????? ????? ?????????? ?????????????? ????:<b00> </b00> </customErrors>
    <customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
    </customErrors>
    						
    ??? ???? ?? ????????? ??? ????? andapplication ??? ?? ?????? ????? ?? defaultRedirect ??????? ??? ?????? ???? ?????
  5. ?? ???? ?? trapped ?? ????????? sentto ??? ???????? ?????? ????? ???? ???, ??????? ?? ?? ?? ???? ???? ?? ??? theuser, ???????? ?? ?? ?????? ?????? ????? ?? ??? ???. htm ????? ?? ????? ???? ?? ???? ?? ????????? ???? ?? ??? ?? ?????? ????? ?? ??? ??? ????? ??? ErrorStatus.htm.Keep ???? ?? ?????? ????? ????? ????? Followingcode 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. ??? ?? ???? ????, ??????? ??????, ????????? ????? ?? ???, andthen ????? AppEvent.aspx ???????? ???? ?????? ???? ??? ??, ?? ?? ErrorStatus.htm ?? ??? ????? ?? ?????????????? ??? ?? ????? ????
?? <customErrors>?????? ??? defaultRedirect ??????? ?? ??? ??? ??? ???????? ?????? ????? ?? ???????? ?? ???? ???, ?????? ?? ??? ????? ??? ????? ?? HTTP ?????? ??? ?? ?????? ???? ?? ??? ?????????????? ???? ?? ??? ????????? ?? ???? ???? ?? ?????? ?? ??? <error>?????? ???? ?? ?????? ???? ??? ?????? ?? ???:<b00> </b00> </error> </customErrors>
<customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
	<error statusCode="404" redirect="filenotfound.htm" />
</customErrors>
				
??? ????. htm ????? defaultRedirect ?? <customErrors>?????? ??? ????????? ???? ???? ?? ?? ????? ??? ???

????? ??? ?? <customErrors>?????? ?????? ?? ??? ??? ???? ??? ?? ?? ??? ??????? ????? ??? ??? ??????? ?????? ????????????? ???? ???? ?? ?? ????????? ???? ?? ??? ????? ???? ???? ??? ?????? ?? ???, ???? ????????? ?? ??????? ?? ??? ???, ?? ?? ???? ???? ?? ?? ASP.NET ???????? ?????? ????? ????? ?? ??? ????? ??? ?? ???? ??????????-???????? ?????? ????? ?? ?????????????? ???? ?? ???? ?? ??? ???? ????? ???? ??? ??????? ????? ???????? ????? ???: </customErrors></customErrors>
  • ??: ????? ? ???? ??? ????? ?????????? ????????? defaultRedirect ????? ?? ?????????????? ????? ?? ??? ??? ??????: ??????? ???? ???? ???
  • ???: ???????????? ?? ????? ??????? ??????? ???? ?? defaultRedirect ????? redirectedto ???? ???? ?? ??? ??? ??????: ????? ???? ???? ???
  • RemoteOnly: ???? ?? ?????????? ?? ??????? ???????? ?? ???? (usinglocalhost) ????? ????? ??????? ??????? ???? ??? ???? ??? ?????????? defaultRedirect ????? ?? ?????????????? ???? ???? ?? ??? ??????: ??????? ?? ??? ????? ???? ???? ???

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

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

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

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

??????

???? ??????? ?? ???, ????? Microsoft ??? ???? ?? ????:
.NET ??? ????? ???????

HttpServerUtility.ClearError ????

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

Microsoft .NET ??? ?????

???

???? ID: 306355 - ????? ???????: 29 ??????? 2013 - ??????: 6.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 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??: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