locked
Testing a custom IHttpHandler using IIS Express *without* installing into GAC RRS feed

  • Question

  • User-153486518 posted

    Hi forum,

    I wrote a Hello World HttpHandler class that I would like to try with IIS Express 10. However, try as I might, I can't get IIS to use my handler. Here is my applicationHost.config:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <configSections>
            <sectionGroup name="system.applicationHost">
                <section name="applicationPools"/>
                <section name="sites"/>
            </sectionGroup>
            <sectionGroup name="system.webServer">
                <section name="globalModules"/>
                <section name="handlers"/>
    			<section name="caching"/>
                <section name="modules"/>
    			<!-- The following section elements are not specified in this file, but without these
    			     declarations, IIS will 500 requests -->
                <sectionGroup name="security">
                    <!--<section name="isapiCgiRestriction"/>-->
                    <section name="access"/>
                    <sectionGroup name="authentication">
                        <section name="anonymousAuthentication"/>
                    </sectionGroup>
                </sectionGroup>
                <section name="serverRuntime"/>
                <sectionGroup name="tracing">
                    <section name="traceFailedRequests" overrideModeDefault="Allow" />
                    <section name="traceProviderDefinitions" overrideModeDefault="Deny" />
                </sectionGroup>
            </sectionGroup>
        </configSections>
        <system.applicationHost>
            <applicationPools>
                <add name="DefaultAppPool" startMode="AlwaysRunning" managedRuntimeVersion="v4.0"/>
            </applicationPools>
            <sites>
    			<site name="Default Web Site" id="1" serverAutoStart="true">
    				<application path="/" applicationPool="DefaultAppPool">
    					<virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\blog" />
    				</application>
    				<bindings>
    					<binding protocol="http" bindingInformation=":8080:localhost" />
    				</bindings>
    			</site>
                <siteDefaults>
                    <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
                    <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
                </siteDefaults>
    		</sites>
        </system.applicationHost>
        <system.webServer>
            <!--By default, the ISAPI module won't load anything. The directive below permits any DLL
                to be run by IIS. In a real enviornment, you would list the specific DLLs that are allowed. -->
            <!--<security>
                <isapiCgiRestriction notListedIsapisAllowed="true"/>
            </security>-->
            <globalModules>
                <add name="AnonymousAuthenticationModule" image="%IIS_BIN%\authanon.dll" />
                <add name="FailedRequestsTracingModule" image="%IIS_BIN%\iisfreb.dll" />
                <!--<add name="IsapiModule" image="%IIS_BIN%\isapi.dll" />-->
            </globalModules>
    		<modules>
    			<add name="AnonymousAuthenticationModule"/>
                <add name="FailedRequestsTracingModule" />
                <!--<add name="IsapiModule"/>-->
    		</modules>
    		<handlers accessPolicy="Read, Execute">
                <!-- The source for a minimal ISAPI extension can be found in the Windows 7 SDK sample repo:
                     https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/web/iis/extensions/simple -->
    			<!--<add name="ISAPI-dll" path="*.dll" verb="*" modules="IsapiModule" resourceType="File" requireAccess="Execute" allowPathInfo="true" />-->
                <add name="HelloWorld" path="*.html" verb="GET" type="HelloWorldIISModule.HelloWorldIISModule, HelloWorldIISModule"/>
    		</handlers>
    
            <tracing>
    
                 <traceProviderDefinitions>
                    
                    <add name="ASPNET" guid="{AFF081FE-0247-4275-9C4E-021F3DC1DA35}">
                        <areas>
                            <add name="Infrastructure" value="1" />
                            <add name="Module" value="2" />
                            <add name="Page" value="4" />
                            <add name="AppServices" value="8" />
                        </areas>
                    </add>
                    <add name="WWW Server" guid="{3a2a4e84-4c21-4981-ae10-3fda0d9b0f83}">
                        <areas>
                            <clear />
                            <add name="Authentication" value="2" />
                            <add name="Security" value="4" />
                            <add name="Filter" value="8" />
                            <add name="StaticFile" value="16" />
                            <add name="CGI" value="32" />
                            <add name="Compression" value="64" />
                            <add name="Cache" value="128" />
                            <add name="RequestNotifications" value="256" />
                            <add name="Module" value="512" />
                            <add name="Rewrite" value="1024" />
                            <add name="FastCGI" value="4096" />
                            <add name="WebSocket" value="16384" />
                        </areas>
                    </add>
                </traceProviderDefinitions>
    
                <traceFailedRequests>
                    <add path="*">
                        <traceAreas>
                            <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                            <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,WebSocket" verbosity="Verbose" />
                        </traceAreas>
                        <failureDefinitions statusCodes="200-999" />
                    </add>
                </traceFailedRequests>
    
            </tracing>
    	</system.webServer>
    </configuration>
    

     

    I have installed the assembly into the bin subdirectory of the blog web app, but I still get this error when trying to request a page from the handler (from the failed request trace);

    ModuleName="IIS Web Core", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="404", HttpReason="Not Found", HttpSubStatus="4", ErrorCode="The operation completed successfully.
    (0x0)", ConfigExceptionInfo=""

    Do I *have* to install my assembly into the GAC in order to use it with IIS Express? It seems that kind of defeats the purpose of a development server, since I have to be privileged to test my assembly.

    Thursday, June 22, 2017 1:43 AM

All replies

  • User1967761114 posted

    Hi  InLocoBansetia,

    Do I *have* to install my assembly into the GAC in order to use it with IIS Express? 

    According to your description, you unnecessary to install the assembly into GAC, you also unnecessary to change the applicationHost.config, I suggest you could just change the web.config in your app.

    See the following example:

    1: Create customizing handler

    namespace TestWeb
    {
        public class HelloWorldHandler : IHttpHandler
        {
            public HelloWorldHandler()
            {
            }
            public void ProcessRequest(HttpContext context)
            {
                HttpRequest Request = context.Request;
                HttpResponse Response = context.Response;
                Response.Write("<html>");
                Response.Write("<body>");
                Response.Write("<h1>Hello from a synchronous custom HTTP handler.</h1>");
                Response.Write("</body>");
                Response.Write("</html>"); 
                Response.End();
            }
            public bool IsReusable
            {
                get { return false; }
            }
        }
    }

    2:Register the customizing handler in web.config.

    <configuration>
      <system.webServer>
         <handlers>
            <add name="HelloWorld" verb="*" path="*.sample" type="TestWeb.HelloWorldHandler"/>
         </handlers>
      </system.webServer>
    </configuration>

    3: In this case, when you using the URL which end with .sample, the customizing handler will work, such as the following URL.

    http://localhost:50612/test.sample

     

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Even

    Friday, June 23, 2017 5:57 AM