Microsoft MVP성태의 닷넷 이야기
VC++: 73. IIS - ISAPI 필터 제작하는 방법 [링크 복사], [링크+제목 복사],
조회: 22061
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

IIS - ISAPI 필터 제작하는 방법

오랜만에 ISAPI 필터를 잠깐 들여다 봤는데요. 제작 방법은 다음의 온라인 문서에서 볼 수 있습니다.

Creating Simple ISAPI Filters
; https://learn.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms525035(v=vs.90)

C 소스코드는 대충 다음과 같이 구성하고,

#define _WIN32_WINNT 0x0400

#include <windows.h>
#include <httpfilt.h>

#define BUFFER_SIZE 2048

BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer)
{
    pVer->dwFilterVersion = HTTP_FILTER_REVISION;
    lstrcpy(pVer->lpszFilterDesc, "...desc...");
    pVer->dwFlags = SF_NOTIFY_ORDER_HIGH | SF_NOTIFY_PREPROC_HEADERS;

    return TRUE;
}

DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD NotificationType, LPVOID pvNotification )
{
    if (NotificationType == SF_NOTIFY_PREPROC_HEADERS)
    {
       // ...
    }

    return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

GetFilterVersion, HttpFilterProc 함수를 def 파일로 export 해주면 됩니다.

LIBRARY "...yours..."

EXPORTS
    HttpFilterProc
    GetFilterVersion

남은 것은 등록 과정인데요. 예전에는 IIS 관리자에서 직접 ISAPI 모듈을 등록해 주어야 했는데, 이제는 web.config에 등록하는 것이 가능해서 해당 DLL 모듈을 IIS 전역적으로 로드하지 않게 만들 수 있습니다. 이로 인해 얻게 되는 부수적인 효과는 잠김 현상이 줄어듦으로써 테스트가 좀 더 쉬워졌다는 점입니다. (심지어 IIS Express에서도 ISAPI 필터가 지원되기 때문에 테스트가 더욱 쉬워졌습니다. ^^)

web.config에 변경되는 부분은 다음의 문서에서 설명하고 있습니다.

ISAPI Filters <isapiFilters>
; https://learn.microsoft.com/en-us/iis/configuration/system.webServer/isapiFilters/

그래서 테스트 하려는 ISAPI DLL 파일의 경로를 다음과 같이 web.config에 명시하면 해당 Web Application만 ISAPI를 로드하게 됩니다.

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>

    <system.webServer>
        <isapiFilters>
            <filter
               name="HeaderFilter"
               enabled="true"
               enableCache="false"
               path="D:\Debug\InterceptHeader.dll" />
        </isapiFilters>
    </system.webServer>

</configuration>




하지만, 직접 해보면 web.config 등록 이후 모든 웹 요청이 다음과 같은 메시지를 떨어뜨리면서 실패하는 현상을 겪게 됩니다.

Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:

Module
IIS Web Core

Notification
Unknown

Handler
ExtensionlessUrl-Integrated-4.0

Error Code
0x80070021

Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

Config File
\\?\D:\WebApplication1\web.config

Requested URL
http://localhost:46931/

Physical Path
D:\WebApplication1

Logon Method
Not yet determined

Logon User
Not yet determined

Request Tracing Directory
d:\Documents\IISExpress\TraceLogFiles\WEBAPPLICATION1(22)

Config Source:
12: <system.webServer>
13: <isapiFilters>
14: <filter


More Information:
This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.

If you see the text "There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined", this error is because you are running a .NET Framework 3.5-based application in .NET Framework 4. If you are running WebMatrix, to resolve this problem, go to the Settings node to set the .NET Framework version to ".NET 2". You can also remove the extra sections from the web.config file.


오류 원인은 간단합니다. 기본적으로는 전역 config 설정에서 ISAPI 필터를 추가하는 것이 금지되어 있기 때문입니다. 이것을 해제하려면 applicationHost.config의 내용을 변경해야 하는데 IIS의 경우 다음의 경로에 있는 파일을 편집하면 됩니다.

C:\Windows\System32\inetsrv\config\applicationHost.config

위의 파일을 관리자 권한으로 실행시킨 메모장에서 열어 다음의 내용을 찾아 Deny에서 Allow로 변경하면 됩니다.

<sectionGroup name="system.webServer">
    ...[생략]...
    <section name="isapiFilters" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
    ...[생략]...

주의할 것은 IIS Express의 경우 사용하는 applicationHost.config 파일의 위치가 다르다는 점입니다. IIS Express는 원본 applicationHost.config 파일을 다음의 경로에 유지하고 있다가,

"C:\Program Files (x86)\IIS Express\AppServer\applicationhost.config"

윈도우에 로그인한 계정에서 최초 IIS Express를 구동하는 시점에 다음의 경로에 복사본을 생성하고 그것을 기반으로 동작합니다. (Visual Studio에서 실행된 경우 이렇게 복사해서 동작하는 것이 기본입니다.)

%userprofile%\documents\iisexpress\config\applicationhost.config

따라서, "%userprofile%\documents\iisexpress\config\applicationhost.config" 파일이 있다면 이걸 수정해 줘야 하고, 없다면 "C:\Program Files (x86)\IIS Express\AppServer\applicationhost.config" 파일을 수정해 주면 됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 1/3/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2013-12-16 01시59분
[ryujh] 안녕하세요.

ISAPI 필터와 HTTP 모듈이 같은(비슷한?) 개념으로 알고 있는데

ISAPI 필터만 가능한 것과 사용해야할 경우 등이 무엇입니까?
반대로 HTTP 모듈만 가능한 것과 사용해야할 경우도 입니다.

파일업로드 관련 기능에서 HTTP 모듈을 구현한 적은 있는데 ISAPI 필터로 바꾼다면 이점이 있다고 보시는지요?

ISAPI 필터를 사용할 수 밖에 없을 때 유지보수라도 필요하니 배워야 할 것 같습니다. 요즘은 개발보다 유지보수를 하고 있는 중입니다.

이상입니다.
[guest]
2013-12-16 10시30분
사실 IIS 7부터 Integrated 모드가 나오면서 ISAPI 필터의 장점이 많이 사라졌습니다. 현재 남은 결정적인 이점이라면 IIS 6에서도 가능하다는 것인데 Windows Server 2003에 대한 서비스 기간 만료 시점이 다가오면서 그나마도 없어질 듯합니다. 파일 업로드 모듈을 굳이 ISAPI로 바꿀 필요는 없어보입니다. ^^ 그리고, ISAPI는 Server Extension과 Filter로 나뉘는데, 말씀하신 파일 업로드 모듈은 Filter가 아닌 Server Extension에 해당합니다.

정리하면, 범용적인 목적의 필터가 필요한 제품을 만드는 경우가 아니고 자사의 솔루션에 넣을 요량이라면 HTTP 모듈이 더 바람직합니다.
정성태

... 31  32  33  34  35  36  37  38  39  40  41  42  [43]  44  45  ...
NoWriterDateCnt.TitleFile(s)
12581정성태3/28/202110591.NET Framework: 1031. WinForm/WPF에서 Console 창을 띄워 출력하는 방법 (2) - Output 디버깅 출력을 AllocConsole로 우회 [2]
12580정성태3/28/20219227오류 유형: 708. SQL Server Management Studio - Execution Timeout Expired.
12579정성태3/28/20219347오류 유형: 707. 중첩 가상화(Nested Virtualization) - The virtual machine could not be started because this platform does not support nested virtualization.
12578정성태3/27/20219605개발 환경 구성: 560. Docker Desktop for Windows 기반의 Kubernetes 구성 (2) - WSL 2 인스턴스에 kind가 구성한 k8s 서비스 위치
12577정성태3/26/202111653개발 환경 구성: 559. Docker Desktop for Windows 기반의 Kubernetes 구성 - WSL 2 인스턴스에 kind 도구로 k8s 클러스터 구성
12576정성태3/25/20219490개발 환경 구성: 558. Docker Desktop for Windows에서 DockerDesktopVM 기반의 Kubernetes 구성 (2) - k8s 서비스 위치
12575정성태3/24/20218514개발 환경 구성: 557. Docker Desktop for Windows에서 DockerDesktopVM 기반의 Kubernetes 구성
12574정성태3/23/202112665.NET Framework: 1030. C# Socket의 Close/Shutdown 동작 (동기 모드)
12573정성태3/22/202110518개발 환경 구성: 556. WSL 인스턴스 초기 설정 명령어 [1]
12572정성태3/22/20219953.NET Framework: 1029. C# - GC 호출로 인한 메모리 압축(Compaction)을 확인하는 방법파일 다운로드1
12571정성태3/21/20219088오류 유형: 706. WSL 2 기반으로 "Enable Kubernetes" 활성화 시 초기화 실패 [1]
12570정성태3/19/202113359개발 환경 구성: 555. openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법
12569정성태3/18/202112313개발 환경 구성: 554. WSL 인스턴스 export/import 방법 및 단축 아이콘 설정 방법
12568정성태3/18/20217782오류 유형: 705. C# 빌드 - Couldn't process file ... due to its being in the Internet or Restricted zone or having the mark of the web on the file.
12567정성태3/17/20219231개발 환경 구성: 553. Docker Desktop for Windows를 위한 k8s 대시보드 활성화 [1]
12566정성태3/17/20219638개발 환경 구성: 552. Kubernetes - kube-apiserver와 REST API 통신하는 방법 (Docker Desktop for Windows 환경)
12565정성태3/17/20217010오류 유형: 704. curl.exe 실행 시 dll not found 오류
12564정성태3/16/20217520VS.NET IDE: 160. 새 프로젝트 창에 C++/CLI 프로젝트 템플릿이 없는 경우
12563정성태3/16/20219535개발 환경 구성: 551. C# - JIRA REST API 사용 정리 (3) jira-oauth-cli 도구를 이용한 키 관리
12562정성태3/15/202110770개발 환경 구성: 550. C# - JIRA REST API 사용 정리 (2) JIRA OAuth 토큰으로 API 사용하는 방법파일 다운로드1
12561정성태3/12/20219287VS.NET IDE: 159. Visual Studio에서 개행(\n, \r) 등의 제어 문자를 치환하는 방법 - 정규 표현식 사용
12560정성태3/11/202110522개발 환경 구성: 549. ssh-keygen으로 생성한 개인키/공개키 파일을 각각 PKCS8/PEM 형식으로 변환하는 방법
12559정성태3/11/202110079.NET Framework: 1028. 닷넷 5 환경의 Web API에 OpenAPI 적용을 위한 NSwag 또는 Swashbuckle 패키지 사용 [2]파일 다운로드1
12558정성태3/10/20219534Windows: 192. Power Automate Desktop (Preview) 소개 - Bitvise SSH Client 제어 [1]
12557정성태3/10/20218210Windows: 191. 탐색기의 보안 탭에 있는 "Object name" 경로에 LEFT-TO-RIGHT EMBEDDING 제어 문자가 포함되는 문제
12556정성태3/9/20217383오류 유형: 703. PowerShell ISE의 Debug / Toggle Breakpoint 메뉴가 비활성 상태인 경우
... 31  32  33  34  35  36  37  38  39  40  41  42  [43]  44  45  ...