Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

ISAPI URL Rewrite

// description of your code here
#include <windows.h>
#include <httpfilt.h>

#define MAX_URL_LEN 4096

BOOL WINAPI GetFilterVersion(HTTP_FILTER_VERSION * pVer)
{
      pVer->dwFlags = (SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT | SF_NOTIFY_PREPROC_HEADERS | SF_NOTIFY_ORDER_HIGH);
      pVer->dwFilterVersion = HTTP_FILTER_REVISION;
      strcpy_s(pVer->lpszFilterDesc,9,"Blah blah blah");
      return TRUE;
}

void ReMapURLs(CHAR* pUrl,HTTP_FILTER_CONTEXT* pfc,PHTTP_FILTER_PREPROC_HEADERS pHeaders)
{
      if (pUrl[0] != '/') return;

      CHAR *iUrl = 0;
      BOOL doSet = FALSE;

      char *sOldUrls[] = { "/test/", "/TEST/" };
      char *sNewUrls[] = { "/go/", "/GO/" };

      for (int i=0; i<2; i++)
      {
            if (iUrl = strstr(pUrl,sOldUrls[i]))
            {
                  doSet = TRUE;
                  memcpy(iUrl,sNewUrls[i],strlen(sNewUrls[i]));
            }
      }

      if (doSet) pHeaders->SetHeader(pfc, "url", pUrl);
}

DWORD WINAPI HttpFilterProc(HTTP_FILTER_CONTEXT *pfc,DWORD NotificationType,VOID * pvData)
{
      PHTTP_FILTER_PREPROC_HEADERS pHeaders;
      DWORD cUrlOrig = MAX_URL_LEN;
      DWORD cUrl = cUrlOrig;
      CHAR rgUrl[MAX_URL_LEN];
      CHAR *pUrl;
      BOOL result;

      switch ( NotificationType )
      {
            case SF_NOTIFY_PREPROC_HEADERS:
                  pHeaders = (PHTTP_FILTER_PREPROC_HEADERS) pvData;
                  result = pHeaders->GetHeader(pfc, "url", rgUrl, &cUrl);

                  if (!result && cUrl > cUrlOrig)
                  {
                        pUrl = (CHAR*)LocalAlloc(0, cUrl);
                        result = pHeaders->GetHeader(pfc, "url", pUrl, &cUrl);
                        if (!result)
                        {
                              LocalFree(pUrl);
                              break;
                        }
                        ReMapURLs(pUrl, pfc, pHeaders);
                        LocalFree(pUrl);
                  }
                  else
                        ReMapURLs(rgUrl, pfc, pHeaders);
                  break;
            default:
                  break;
      }
      return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

Adding Comments to the IIS Log

Adding Comments to the IIS Log

A simple way to provide more information to the IIS log files is to append it yourself with the Response.AppendToLog method. By using Session and Application events you can place keywords that you can later use when search the files. You might even be able to train some of the analysis programs to understand you keywords and hopefully provide more meaningful stats.

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
        Response.AppendToLog("test")
    End Sub

There are some restrictions, however. Since the data you provide is appended to the URI Query portion of the log file, you are limited to 80 characters. In addition, you cannot use commas since they are a delimiter for some of the log file formats. Also, if you anticipate that there will be other querystring elements you may want to prepend your string with an ampersand.

----

From http://psacake.com/web/ht.asp:
While trying to come up with new ways to record things that are happening on my Web server, I came across the Response Objects AppendToLog Method. This method allows you to write directly to the IIS Log File using only one line of code. This has come in handy for error trapping and troubleshooting. The following is a piece of sample code that writes a single entry to the log file:

     Response.AppendToLog "Database Being Accessed"


The above line would write the following to your IIS log file:

127.0.0.1, -, 01/01/00, 12:00:34, W3SVC1,WEBSERVER,
127.0.0.1, 161342, 485, 228, 200, 0, get, /somefile.asp, Database Being Accessed

Remember that the IIS log file is a comma-delimited file, and you should try to avoid using commas in the data string you pass to the log file.

----

Rant From http://sqljunkies.com/WebLog/ktegels/archive/2004/01/21/795.aspx:
Since we already have IIS logging turned on, it just made sense to log to that. When we needed to harvest the data for making test case, we could just parse the logs. So, I turned a hopeful eye towards HttpResponse.AppendToLog (which is available to us in ASP.NET as Response.AppendToLog) thinking it might at least be a Copper Bullet. It works, but, where it decides to put your entry in the log could be a problem. Data written to these logs using this method is inserted where the cs-uri-query field would be rather than at the end of the record.

I suppose that this behavior makes sense if you stop to consider that the cs-uri-query field should be blank, null or otherwise meaningless for POSTs (normally). Of course, the de facto RFC doesn't say that, so IIS can get by with it.

Unless of course, you're GETting, not POSTing. But in those cases, you really don't need this trick anyway.

My whole problem with this that the "Extended Log File Format" does offer a more proper place to put this data: x-Comment. If X-Comment appeared at the end of a line, it likely wouldn't break most log parsers, and we'd have a sensible place to look for this.

Using Scheme in ASP

;The following example is in VBScript. Any scripting language that uses com objects will be similar
;1 Install PLT Scheme - it will register the dlls
;2 Control Panel > Administrative Tools > Component Services
; My Computer > DCOM Config > MzCOM
; Properties > Security > Launch and Activation Permissions > Customize
; Add Everyone or IUSR_<Computername> Allow Local Launch, Local Activation

;Output
;(define test (lambda () (+ 1 2 3 4 5)))
;15
strScheme = "(define test (lambda () (+ 1 2 3 4 5)))" 'Test Function
    
Set objScheme = Server.CreateObject("MzCOM.MzObj")   
result = objScheme.Eval(strScheme) 
result = objScheme.Eval("(test)")  'It remembers the function
Set objScheme = Nothing

Response.Write(strScheme & "<br>" & result & "<br>") 'Display Results

HTTP 301 - Moved Permanently

<script runat="server">
private void Page_Load(object sender, System.EventArgs e) {
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location", "http://www.new-url.com");
}
</script>

http://www.webconfs.com/how-to-redirect-a-webpage.php

Server unavailable fixup

REM This batch file addresses "Server unavailable" error
@echo off 

REM "Changing to the Framework install directory"
cd /d C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322

echo "Stopping IIS"
iisreset /stop 
echo "----------------------"

echo "Stopping the ASP.NET state service if it is running"
net stop aspnet_state
echo "----------------------"

echo "Re-registering ASP.NET"
aspnet_regiis -i 
echo "----------------------"

echo "Restarting IIS"
iisreset /start 
echo "----------------------"
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS