asp.netweb-configglobal-asaxhttpapplication

How to create a barebones HttpApplication for ASP.Net (without Webforms or MVC)


Ok I am wanting to learn more about how ASP.Net works under the hood. I mean beneath MVC or Webforms and other such frameworks.

Basically I want to know how those frameworks are wired onto ASP.Net so that they work with IIS. What would be the bare minimum for creating a simple HttpApplication which worked with IIS and used neither MVC or Webforms? What is the bare minimum required to be in the Web.config? What would be added to Global.asax?


Solution

  • I actually meant to answer this question myself as I've done it. smartcaveman provides part of the solution.

    What I did for web.config:

    <?xml version="1.0"?>
    <configuration>
        <system.web>
           <compilation debug="true">
           </compilation>
        </system.web>
        <system.codedom>
            <compilers>
                <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                    <providerOption name="CompilerVersion" value="v3.5"/>
                    <providerOption name="WarnAsError" value="false"/>
                </compiler>
            </compilers>
        </system.codedom>
        <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0. It is not necessary for previous version of IIS.
        -->
        <system.webServer>
        </system.webServer>
        <runtime>
        </runtime>
    </configuration>
    

    and then in global.asax:

    protected virtual void Application_BeginRequest (Object sender, EventArgs e)
    {
        if (Request.Url.AbsolutePath == "/test") 
        {
            var h=new Test1(); //make our Test1.ashx handler
            h.ProcessRequest(Context);
        }
        else
        {
            Response.ContentType = "text/plain";
            Response.Write("Hi world!");
        }
        CompleteRequest();
    }
    

    and then you can use ASP.Net handlers for content(as shown) or you can of course write your own replacement and write to Response yourself.

    For reference, my working framework I made with a custom routing engine (and view engine) is in subversion here