Wie managed SharePoint den Datei Upload und Download ?


Bei den Recherchen zum Thema Dateiverschlüsselung hat sich mir die Frage gestellt wie der Upload und Download von Dateien in Dokumentenbibliotheken auf Webserver Ebene handhabt.

Um hier weiter zu kommen habe ich mir ein http module geschrieben das einfach die wichtigsten Daten der Requests in eine Logdatei schreibt - hier der Quellcode der Klasse:

using System;
using System.Web;
using System.Diagnostics;

namespace LogWriter 
{
    /// <summary>
    /// 
    /// </summary>
    public class LogModule : IHttpModule
    {
        System.IO.StreamWriter logWriter;
        HttpApplication applicationContext;
        EventHandler beginRequestEventHandler;
        EventHandler endRequestEventHandler;
        String logName;

    public void Init(HttpApplication context)
    {
      //Store file name for later use.
      logName = context.Context.Request.PhysicalApplicationPath + "log.txt";

      //Open file and write information.
      logWriter = new System.IO.StreamWriter(logName, true);
      logWriter.WriteLine("Date :" + System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss"));
      logWriter.WriteLine("Event : Init");
      logWriter.Flush();
      logWriter.Close();

      //Store for access in other events.
      applicationContext = context;
      beginRequestEventHandler = new System.EventHandler(this.OnBeginRequest);
      applicationContext.BeginRequest += beginRequestEventHandler;
      endRequestEventHandler = new System.EventHandler(this.OnEndRequest);
      applicationContext.BeginRequest += endRequestEventHandler;
    }

    public void Dispose()
    {

      //Open file and write information.
      logWriter = new System.IO.StreamWriter(logName, true);
      logWriter.WriteLine("");
      logWriter.WriteLine("Date :" + System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss"));
      logWriter.WriteLine("Event : Dispose");
      logWriter.WriteLine("");
      logWriter.Flush();
      logWriter.Close();

      //Clean-up.
      applicationContext.BeginRequest -= beginRequestEventHandler;
      beginRequestEventHandler = null;
      applicationContext.EndRequest -= beginRequestEventHandler;
      beginRequestEventHandler = null;
    }

    protected void OnBeginRequest(object sender, EventArgs e)
    {
      //Open file and write log information.
      logWriter = new System.IO.StreamWriter(logName, true);
      logWriter.WriteLine("");
      logWriter.WriteLine("Date :" + System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss"));
      logWriter.WriteLine("Event : Application_BeginRequest ");
      logWriter.WriteLine("HTTP :" + applicationContext.Request.HttpMethod.ToString());
      logWriter.WriteLine("UserAgent : "  + applicationContext.Context.Request.UserAgent);
      logWriter.WriteLine("HostAddress : " + applicationContext.Context.Request.UserHostAddress);
      logWriter.WriteLine("HostName : " + applicationContext.Context.Request.UserHostName);
      logWriter.WriteLine("SiteURL : " + applicationContext.Context.Request.Url.ToString());
      if (applicationContext.Request.CurrentExecutionFilePath != null)
      {
        logWriter.WriteLine("File : " + applicationContext.Request.CurrentExecutionFilePath.ToString());
      };
      logWriter.WriteLine("");
      logWriter.Flush();
      logWriter.Close();
    }
        protected void OnEndRequest(object sender, EventArgs e)
        {
            //Open file and write log information.
            logWriter = new System.IO.StreamWriter(logName, true);
            logWriter.WriteLine("");
            logWriter.WriteLine("Date :" + System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss"));
            logWriter.WriteLine("Event : Application_EndRequest ");
            logWriter.WriteLine("HTTP :" + applicationContext.Request.HttpMethod.ToString());
            logWriter.WriteLine("UserAgent : " + applicationContext.Context.Request.UserAgent);
            logWriter.WriteLine("HostAddress : " + applicationContext.Context.Request.UserHostAddress);
            logWriter.WriteLine("HostName : " + applicationContext.Context.Request.UserHostName);
            logWriter.WriteLine("SiteURL : " + applicationContext.Context.Request.Url.ToString());
            if (applicationContext.Request.CurrentExecutionFilePath != null)
            {
                logWriter.WriteLine("File : " + applicationContext.Request.CurrentExecutionFilePath.ToString());
            };
            logWriter.WriteLine("");
            logWriter.Flush();
            logWriter.Close();
        }

    }
   
}

Das Ganze mit Visual Studio 2008 übersetzt und die DLL in den GAC gepackt. In der web.config der SharePoint Webapplication noch folgenden Eintrag hinzugefügt:

        <httpModules>
            <add type="LogWriter.LogModule" name="LogWriteModule"/>
        </httpModules>

Nun kann man in der Logdatei wunderbar verfolgen wie Uploads und Downloads von Dateien funktionieren.

viel Spass

Sven

Comments (2)
  1. In meinem vorherigen Blogpost habe ich beschrieben wie man mit einem http module dem Upload und Download

Comments are closed.

Skip to main content