How to create barebone HttpApplication for ASP.Net (without web forms or MVC)

Ok, I want to learn more about how ASP.Net works under the hood. I mean by MVC or Webforms and other such frameworks.

Basically, I want to know how these structures connect to ASP.Net so that they work with IIS. What would be the minimum minimum for creating a simple HttpApplication that worked with IIS and did not use either MVC or Webforms? What is the minimum minimum required to work in Web.config? What will be added to Global.asax?

+5
source share
2 answers

, . Smartcaveman .

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>

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();
}

ASP.Net ( ), , , Response .

, ( ), subversion

+2

, IHttpHandler. :

public interface IHttpHandler
{
    void ProcessRequest(HttpContext context);
    bool IsReusable { get; }
}

HttpContext - , . , . Server . Request HttpRequest, Response .

- Reflector HttpContext , .

:

public class HelloWorldHandler: IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.Write("Hello World");
        context.Response.End();
    }

    public bool IsReusable
    {
        get { return false; }
    }
}

Global.asax . , , , IHttpModule.

web.config - , IIS 7 - . , HttpHandler, .

web.config , , . , , web.config, IIS. . http://msdn.microsoft.com/en-us/library/b5ysx397(v=VS.85).aspx.

, . , , .

+6

All Articles