CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2000
    Location
    Indore (MP) INDIA.
    Posts
    356

    Problem with Debugging ISAPI Extension on IIS 6.0 ...

    Hello All,

    I have written a small & Simple ISAPI extension that simply print "Hello" in the browser. The code that I used is below in the code section.

    I wanted to Write to a file from the ISAPI extension. So I tried to set permissions of the folder to specify WRITE in addition to READ permission. This is done using the IIS Manager Snap-in. After calling the extension's DLL from the browser, I can see the Hello world in the browser and 200 status code in IIS W3C log file.

    The only thing I can't see is the log file at C:\.

    Code:
    BOOL WINAPI DllMain(IN  HINSTANCE hinstDll, IN  DWORD dwReason, IN  LPVOID lpvContext)
    {
    	return TRUE;
    }
    
    BOOL WINAPI GetExtensionVersion(OUT  HSE_VERSION_INFO *pVer)
    {
    	const CHAR szExtensionInfo[] = "SGN: ISAPI Extension" ;
    
    	pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR); // HSE_VERSION;
    	strncpy_s(pVer->lpszExtensionDesc, HSE_MAX_EXT_DLL_NAME_LEN, szExtensionInfo, strlen(szExtensionInfo));
    
    	return TRUE;
    }
    
    DWORD WINAPI HttpExtensionProc(IN  EXTENSION_CONTROL_BLOCK  *pECB)
    {
    	static char szMessage[] =  "<HTML><HEAD><TITLE> Hello World </TITLE></HEAD>\r\n" 
    		"<BODY><H2>Hello from Simple ISAPI Extension DLL!</H2>\r\n</BODY></HTML>\r\n\r\n"; 
    
    	HSE_SEND_HEADER_EX_INFO HeaderExInfo; 
    
    	HeaderExInfo.pszStatus = "200 OK"; 
    	HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n"; 
    	HeaderExInfo.cchStatus = strlen(HeaderExInfo.pszStatus); 
    	HeaderExInfo.cchHeader = strlen(HeaderExInfo.pszHeader); 
    	HeaderExInfo.fKeepConn = FALSE; 
    
    	pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &HeaderExInfo, NULL, NULL); 
    
    
    	HANDLE hLogFile = CreateFile(TEXT("C:\\RequestLog.txt"), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) ;
    	if (hLogFile != NULL && hLogFile != INVALID_HANDLE_VALUE)
    	{
    		DWORD dwWritten = 0 ;
    		SetFilePointer(hLogFile, 0, NULL, FILE_END) ;
    		if (WriteFile(hLogFile, szMessage, strlen(szMessage), &dwWritten, NULL) == FALSE)
    		{
    			// Write to Event Log then ... (if possible)
    		}
    		CloseHandle(hLogFile) ;
    	}
    
    
    	DWORD dwBytesToWrite = strlen( szMessage ); 
    	pECB->WriteClient( pECB->ConnID, szMessage, &dwBytesToWrite, 0 ); 
    
    	return HSE_STATUS_SUCCESS; 
    }
    
    BOOL WINAPI TerminateExtension(IN DWORD dwFlags) 
    { 
    	return TRUE; 
    }
    I have a few questions in my mind after this:
    - Can someone let me know, what can I do to troubleshoot the issue ? The machine with IIS has the MS VC Remote Debugger (MSVCMON.exe) installed there. However, After connecting to IIS, My Visual Studio 2008 freezes until Infinity.

    - How do I debug and confirm that which functions are getting failed ?
    - How do I log information from inside of my ISAPI extension ?
    - Is it possible to log entries into Window Event Log from inside of my ISAPI extension ?
    - What else permissions are required for my ISAPI extension to be able to write to file ?


    I know, lots of questions but Your Answer would be of great help in clearing the clouds and will be appreciated.

    Thanks,

    (*Vipul)() ;

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Problem with Debugging ISAPI Extension on IIS 6.0 ...

    OPEN_ALWAYS implies the file already exists.
    Best regards,
    Igor

  3. #3
    Join Date
    May 2000
    Location
    Indore (MP) INDIA.
    Posts
    356

    Re: Problem with Debugging ISAPI Extension on IIS 6.0 ...

    Thanks Igor,

    However I used OPEN_ALWAYS after seeing the following description from MSDN. I think what you said is OPEN_EXISTING:

    OPEN_ALWAYS (4)

    Opens a file, always.

    If the specified file exists, the function succeeds and the last-error code is set to ERROR_ALREADY_EXISTS (183).

    If the specified file does not exist and is a valid path to a writable location, the function creates a file and the last-error code is set to zero.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Problem with Debugging ISAPI Extension on IIS 6.0 ...

    Yeah, my bad, sorry. But anyway, did you give a try with already existing file?
    Best regards,
    Igor

  5. #5
    Join Date
    May 2000
    Location
    Indore (MP) INDIA.
    Posts
    356

    Re: Problem with Debugging ISAPI Extension on IIS 6.0 ...

    Yes Igor, I tried it with an existing file as well, but the result was same :-(

    Then Instead of trying on a remote IIS server which doesn't have any debugger installed, I installed IIS 7 on my local development machine and tried to run the ISAPI extension on it.

    The VS 2008 (C++) is now able to attach to Process w3wp.exe (IIS7). The process now break in the VC++ debugger.

    What I can see now is that -
    Code:
    HANDLE hLogFile = CreateFile(TEXT("C:\\RequestLog.txt"),  .  .  .
    has the problem. it is returning 0xFFFFFFFF in hFile and on calling GetLastError() it returns 5.

    I have changed the path C:\\RequestLog.txt to C:\\IsApi\\temp\\RequestLog.txt and given READ+WRITE+EXECUTE+MODIFY permissions to the user LOCAL_SERVICE under which the service World Wide Web Publishing is executing.

    Yet it is the same .... No Luck :-(

    Any thing that you can see here ...

    Regards,

    (*Vipul)() ;
    (*Vipul)() ;

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Problem with Debugging ISAPI Extension on IIS 6.0 ...

    on calling GetLastError() it returns 5
    Seems like extension is not allowed to write to local path
    net helpmsg 5

    Access is denied.
    Last edited by Igor Vartanov; May 4th, 2010 at 10:04 AM.
    Best regards,
    Igor

  7. #7
    Join Date
    May 2000
    Location
    Indore (MP) INDIA.
    Posts
    356

    Re: Problem with Debugging ISAPI Extension on IIS 6.0 ...

    Yes, Definitely its Access Denied. Though I have already given READ+WRITE+EXECUTE+LIST+MODIFY permission to the user LOCAL_SERVICE. The WWW service executes under user LOCAL_SERVICE.
    (*Vipul)() ;

  8. #8
    Join Date
    May 2000
    Location
    Indore (MP) INDIA.
    Posts
    356

    Thumbs up Re: Problem with Debugging ISAPI Extension on IIS 6.0 ...

    I ran SysInternal's ProcMon utility on the machine where the WWW service was running. I enabled file system monitoring while disabling other type of monitoring.

    I observed that an attempt to CreateFile() was failed with ACCESS_DENIED error on File RequestLog.txt. The request was Impersonating the UserId IIS_IUSR.

    So then, I granted READ+WRITE permissions on the said folder to the impersonated User/Group and BINGO !!

    It works! Ever since I saw permission denied, I was trying to figure out why the request is failing despite the fact that I have already granted permission.

    Thanks Igor for discussing the problem ...
    (*Vipul)() ;

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured