tags:

views:

37

answers:

2

I wanne write a web server by C# which can handle asp requests. how can I do it?

+2  A: 

As others have asked, you should be using the Visual studio built in server or other webservers like IIS or apache.

If you are looking to learn the basics (from an educational viewpoint), you can check out the sample here:

http://www.asp.net/downloads/archived-v11/cassini

Raj Kaimal
+4  A: 

The ASP.Net runtime can be hosted by any process you'd like, and it's actually quite simple to do. The key is in using the HttpRuntime class.

From my answer on the "Hidden Features of ASP.Net" thread:

public class HostingClass : MarshalByRefObject
{
    public void ProcessPage(string url)
    {
        using (StreamWriter sw = new StreamWriter("C:\temp.html"))
        {
            SimpleWorkerRequest worker = new SimpleWorkerRequest(url, null, sw);
            HttpRuntime.ProcessRequest(worker);
        }
                    // Ta-dah!  C:\temp.html has some html for you.
    }
}

And then in your webserver class:

HostingClass host = ApplicationHost.CreateApplicationHost(typeof(HostingClass), 
                                            "/virtualpath", "physicalPath");
host.ProcessPage(urlToAspxFile); 

Obviously this isn't really a webserver, but what it shows is the processing of a request for an aspx page, parsing the page, and dumping the result to a text file.

To write a real server you'd obviously need to get into listening and accepting requests from socket connections, but the point is that you can easily leverage the asp.net runtime to crunch your pages for you, and write all your own logic for how to serve them up.

womp