Back to "Little hit tracking module for .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

Little hit tracking module for .TEXT 0.95 blogs...

Tuesday, 06 July 2004

OK, terribilmente documentato, ma funziona...questa è solo la fonte per un po 'HttpModule che traccia colpi ad un blog .TEXT - abbastanza semplice, ma dovrebbe dare a chiunque voglia farlo un inizio. Pubblicare una versione più completa ad un certo punto (principalmente solo per verificare come questa pelle si comporta con il codice inviato;-))

utilizzo del sistema;

utilizzo di System.Web;

utilizzo di System.Data;

utilizzando System.Data.SqlClient;

utilizzo di Dottext.Framework;

utilizzando System.Collections.specializzata;

utilizzo di System.IO;

utilizzo di System.Text;

utilizzando System.Xml.Serialization;

utilizzo di System.Threading;

utilizzo di System.Net;

utilizzando Microsoft.ApplicationBlocks.Data;

Namespace ExtraControlli

{

///

/// Descrizione riassuntiva per VisualizzaTrackModulo.

///

classe pubblica ViewTrackModule : IHttpModule

{

#regione IHttpModule Members

vuoto pubblico Init(Contesto HttpApplication)

{

Context.EndRequest += new EventHandler(context_EndRequest);

}

vuoto pubblico Smaltire()

{

// TODO: Aggiungi VisualizzaTrackModule.Dispose l'implementazione

}

#endregion

///

/// Ok, un po' insolito... ma ho bisogno che l'oggetto BlogConfig sia disponibile per l'accesso DB...

///

///

///

contesto vuoto privato_EndRequest(mittente oggetto, EventArgs e)

{

HttpApplication httpApp = mittente come HttpApplication;

System.Uri ur = httpApp.Request.UrlReferrer;

stringa testHost = stringa.Vuoto;

stringa questoHost = httpApp.Richiesta.ServerVariables["SERVER_NAME"];

if(ur != null)

{

testHost = ur.Host;

}

if(testHost != thisHost)

{

HttpRequest re = httpApp.Request;

LogToDBDel del = nuovo LogToDBDel(LogToDB);

IAsyncResult ar = del.BeginInvoke(re,null,null);

}

}

delegato privato vuoto LogToDBDel(HttpRequest re);

vuoto privato LogToDB(HttpRequest re)

{

stringa m_connectionString = Dottext.Framework.Configuration.BlogConfigurationSettings.Instance().BlogProvider.DbProvider.ConnectionString;

stringa clientIP = re.UserHostIndirizzo;

if(!clientIP.StartsWith("192.") && !clientIP.StartsWith("10."))

{

stringa clientUserAgent = re.UserAgent;

stringa clientReferer = re.ServerVariables["HTTP_REFERER"];

stringa clientHostName = stringa.Vuoto;

prova

{

clientHostName = Dns.GetHostByAddress(clientIP).HostName;

}

catture(Eccezione)

{

clientHostName = re.UserHostName;

}

stringa clientQueryString = re.RawUrl;

SqlParameterCity name (optional, probably does not need a translation)[] sqlParams = SqlHelperParameterCache.GetSpParameterSet(m_ConnessioneString, "pr_Blog_SaveEntryStats");

sqlParamsCity name (optional, probably does not need a translation)[0].Value = clientIP;

sqlParamsCity name (optional, probably does not need a translation)[1].Value = clientUserAgent;

sqlParamsCity name (optional, probably does not need a translation)[2].Value = clientHostName;

sqlParamsCity name (optional, probably does not need a translation)[3].Value = clientQueryString;

sqlParamsCity name (optional, probably does not need a translation)[4].Value = DateTime.Now;

sqlParamsCity name (optional, probably does not need a translation)[5].Value = clientReferer;

prova

{

SqlHelper.EseguiNonQuery(m_ConnectionString, CommandType.StoredProcedure, "pr_Blog_SaveEntryStats," sqlParams) ;

}

catture(Eccezione)

{

}

}

}

}

}

Come al solito, questo ha bisogno di una voce nel web.config per agganciare nel modulo:

<httpModules> <aggiungi nome="RequestLogger" type="ExtraControls.ViewTrackModule, ExtraControls"/> </httpModules>

logo

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