Back to "Kleine hit tracking module voor .TEXT 0.95 blogs..."

This is a viewer only at the moment see the article on how this works.

To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk

This is a preview from the server running through my markdig pipeline

Imported mostlylucidcouk

Kleine hit tracking module voor .TEXT 0.95 blogs...

Tuesday, 06 July 2004

OK, verschrikkelijk gedocumenteerdM SK1 maar het werkt... dit is gewoon de bron voor een kleine HttpModule die stopt op hits naar een MSC3TEXT blog - vrij eenvoudig, maar zou iedereen die het wil doen een start moeten geven.

Met behulp van System;

Met behulp van System.Web;

Met behulp van System.Data;

Met behulp van System.DataM SK1SqlClient;

Met Dottext.Framework;

Met behulp van het systeem.Collecties.SpecializedM SK2

Met behulp van System.IO;

Met behulp van het systeem.Text;

Met behulp van het systeem.Xml.SerialisatieM SK2

Met behulp van System.Threading;

Met behulp van System.Net;

Met behulp van Microsoft.ApplicationBlocks

Namespace ExtraControls

{

///

/// Samenvattingsbeschrijving voor ViewTrackModule

///

publieke klas ViewTrackModule : IHttpModule

{

#region IHttpModule Members

public void Init(HttpApplication context)

{

context.EndRequest += nieuwe EventHandlerM SK2context_EndRequest);

}

Publiek leegte Verwijdering()

{

// TODO : Voeg ViewTrackModule toe.Verwerking opdelen

}

#endregion

///

/// Ok, bit ongebruikelijk ...maar ik heb het BlogConfig-object nodig om beschikbaar te zijn voor de DB-toegang

///

///

///

Private void context_EndRequestM SK1object-versender, EventArgs eMSC3

{

HttpApplication httpApp = stuurder als HttpsApplication;

System.Uri ur = httpAppMSC2RequestM SK3UrlReferrerMスク4

String testHost = string.VleegM SK2

string thisHost = httpApp.RequestM SK2ServerVariables["SERVeerder_NAME"];

Als(ur M SK1 null)

{

testHost = ur.HostM SK2

}

Als(testHost != dezeHostM SK2

{

HttpRequest re = httpApp.RequestM SK2

LogToDBDel del = nieuwe Log ToDBDel(LogToDBM SK2

IAsyncResult ar = del.BeginInvokeMST2reM ST3nullM st4null~M st5

}

}

private delegate void LogToDBDel(HttpRequest re);

private void LogToDB(HttpRequest re)

{

String m_connectionString

string clientIP = re.UserHostAddressM SK2

Als(!kliënt IP.Begint metM SK2 && ≥!klient IP.Be Begint met("10."))

{

string clientUserAgent = re.UseragentM SK2

string clientReferer = re.ServerVariables["HTTP_VERwijzer"];

string clientHostName = string.VleegM SK2

Probeer

{

clientHostName = Dns.GetHostByAddressMska2clientIPM Ska3HostnameMske4

}

Catch(Excepte)

{

clientHostName = reM SK1UserHost Name;

}

string clientQueryString = reM SK1RawUrl;

SqlParameter[] sqlParams = SqlHelperParameterCacheM SK2GetSpParameterSet(m_connectionString_Blog_SaveEntryStats"); 

sqlParams[0].Werk =kliënt IP;

sqlParams[1].Werk =kliëntUserAgent;

sqlParams[2].Werk =clientHostName;

sqlParams[3].Werk =clientQueryString;

sqlParams[4].Wert = Datum en tijd.NuM SK3

sqlParams[5].Werk =kliëntreferenaar;

Probeer

{

SqlHelper.ExecuteNonQuery(m_connectionString,CommandtypeM SK2StoredProcedureMSC3 "pr_Blog_SaveEntryStats

}

Catch(Excepte)

{

}

}

}

}

}

Zoals gewoonlijk, heeft dit een invoer nodig in het web.config om in de module te hakkenM SK2

<http-modules> <Voeg naam toe="RequestLogger " type="ExtraControlsM SK3ViewTrackModuleMSC4 ExtraControls> </httpmodules>

logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.