asp.net同以前的asp一樣,當(dāng)服務(wù)器上發(fā)生了一個運(yùn)行時間或編譯時間錯誤時,就會生成一個html 錯誤頁面。但是與asp不同,asp.net格外關(guān)注的是:要確保在默認(rèn)狀態(tài)下,不會因?yàn)檫@個錯誤的發(fā)生而泄露“安全”信息。尤其是如果你從一個遠(yuǎn)程機(jī)器上點(diǎn)擊服務(wù)器的話?!皁ut of the box”型的錯誤處理設(shè)置將不會導(dǎo)致顯示遠(yuǎn)程機(jī)器的編譯器信息、泄露配置信息、文件名、堆棧記錄 、源代碼或線性數(shù)據(jù)。相反,遠(yuǎn)程用戶只會看到一個如“發(fā)生了應(yīng)用程序錯誤”的普通信息。要想查看錯誤細(xì)節(jié),用戶必須要:1)從本地服務(wù)器再次點(diǎn)擊頁面,或者是 2)在機(jī)器或應(yīng)用程序的config.web文件中修改配置的設(shè)置來允許遠(yuǎn)程訪問:
<%@ import namespace="system.diagnostics" %> <script language="vb" runat=server> sub application_error(sender as object, e as eventargs) 'obtain the url of the request dim pageurl as string = request.path 'obtain the exception object for the error dim errorinfo as exception = server.getlasterror() 'construct error message to write to nt event log dim message as string = "url " & pageurl message = message & " error: " message = message & errorinfo.tostring 'nt event log name to write message to dim logname as string = "mycustomlog" 'create event log if it doesn’t exist if (not eventlog.sourceexists(logname)) then eventlog.createeventsource(logname, logname) end if 'fire off to event log dim log as new eventlog log.source = logname log.writeentry(message, eventlogentrytype.error) end sub </script>