|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
ASP由于使用了COM组件所以它会变的十分强大,但是这样的强大由于WindowsNT系统最初的设计问题而会引发大量的安全问题。只要在这样的组件或是操作中一不注意,哪么外部攻击就可以取得相当高的权限而导致网站瘫痪或者数据丢失;asp+|显现Writtenby:ChristophWille
Translatedby:BernhardSpuida
Firstpublished:8/11/2000
UnderWindows2000(orNT)theEventLogisaboutthemostimportantsourceofinformationforthe
administratorbecausealleventsthatoccurredareloggedthere-fromsuccesstocatastrophicalfailure.
Andasitissoimportant,whatwouldbemoreobviousthantomakeitaccessibleviatheweb?
TheEventViewershouldbefamiliartonearlyeveryone(seepicture).InthisarticleIwilldemonstrate
howthelistofentriescanbeemulatedveryelegantlyusingASP.NETandthe.NETFrameworkSDK.Asan
exerciseforthereaderIwillleavetheconstructionofapageforthefulldetailsofanentry.
TheuseofthesourcecodeinthisarticlerequirestheMicrosoft.NETFrameworkSDKinstalledona
Webserver.IalsopresumethatthereaderisfamiliartosomedegreewiththeC#programminglanguage.
TheBruteForceMethod
Whenwehavetobequickanddirty,knowledgefromthedaysofASPcanverywellbeusedtogeneratea
listofevents(Evenwithatable,thoughthisexampledoesntdothat).Thenameoftheprogramisthe
nameofthegame:simple.aspx.
<%@PageLanguage="C#"%>
<%@ImportNamespace="System.Diagnostics"%>
<%
EventLogaLog=newEventLog();
aLog.Log="System";
aLog.MachineName=".";//LokaleMaschine
stringstrImage="";//IconfürdasEvent
Response.Write("<p>Thereare"+aLog.Entries.Count+
"entriesintheSystemeventlog.</p>");
foreach(EventLogEntryentryinaLog.Entries)
{
switch(entry.EntryType)
{
caseEventLogEntryType.Warning:
strImage="warning.png";
break;
caseEventLogEntryType.Error:
strImage="error.png";
break;
default:
strImage="info.png";
break;
}
Response.Write("<imgsrc=""+strImage+"">|");
Response.Write(entry.TimeGenerated.ToString()+"|");
Response.Write(entry.Source+"|");
Response.Write(entry.EventID.ToString()+"
");
}
%>
TheclassesfortheEventLogarefoundintheNamespaceSystem.Diagnosticswhichisboundinatthe
beginningofthepage.Openingthelogisinitselfstraightforward:createanewEventLogobject,specify
theLogandtheMachineName("."isthelocalmachine).AndwerereadytoreadfromtheEventLog.
Thisisdoneinaforeachloop.Tomakethelistinglessunimaginative,Iputthecorrecticonbeforeeach
entry.Bytheway,thelistingofentriesisthereverseoftheusualorderintheEventViewer:here,the
oldestentriesarelistedfirst.
MoreelegantwiththeDataGrid
ASP.NETcomeswithmanyinnovations,especiallyfordisplayingdata.Andthegoodpartaboutthatisthat
thedatadoesnotalwayshavetocomeoutofadatabase.ThisalsoistruefortheDataGridWebControl
which,asthenamesays,createsatable(grid)outofthedata.Theonlyrequirementisthatthedata
sourcesupportstheICollectioninterface-andtheEntriesCollectionoftheEventLogdoesjustthat.
Thefollowingsourcecode(datagrid.aspx)showshowsimpleusingtheDataGridis:
<%@PageLanguage="C#"%>
<%@ImportNamespace="System.Diagnostics"%>
<scriptlanguage="C#"runat="server">
voidPage_Load(Objectsender,EventArgse)
{
EventLogaLog=newEventLog();
aLog.Log="System";
aLog.MachineName=".";
LogGrid.DataSource=aLog.Entries;
LogGrid.DataBind();
}
</script>
<bodybgcolor="#ffffff">
<h3>SystemEventLog</h3>
<formrunat="server">
<ASP:DataGridid="LogGrid"runat="server"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>
</form>
</body>
</html>
TheDataGridControlonlycontainsformattinginstructions,nothingelse.TheGridis</p>优点:简单易学、开发速度快、有很多年“历史”,能找到非常多别人做好的程序来用、配合activeX功能强大,很多php做不到的asp+activeX能做到,例如银行安全控件 |
|