Cassini source code analysis
(1)
2004-11-10
Why analyze cassini?
Cassini is an open source project on ASP.NET. It is primarily given an ASP.NET execution environment that is detached from IIS. The project demonstrates how to create a web server and run an ASP.NET application.
Studying Cassini can understand:
1. How to implement the web server in .NET environment, pay attention to those issues
2, the implementation of ASP.NET
3, learn about appdomain's execution concept
installation
No problem, default
run
There is a problem, mainly my .NET Framework is 1.0.3705 and the compiled Cassini.dll downloaded by the system is compiled under V1.1.4322 and is more troublesome. So start back to see the Framework for V1.1.4322 when you start.
And my goal is to analyze this procedure, how do you do?
Since I got the entire source code, I should be familiar with theory and can master the entire system. I build a project, join all .CS files and resource files to an item, and delete the original project default Form1 because CassiniWebServer. Cs already has a Main entrance.
Debug, solve problems
1. Compile OK, but cannot start, it is lacking .ico file. Isn't it going to join the project? It turns out that our compiler is in the bin / debug directory, so I copied the CassiniWebserver..ico file to bin / debug / go to the next
2, enter the ASP.NET application root directory, port, execution point, OK, click Start, an error, it seems to tell my port is occupied. impossible! My 80-port 8080 port is not occupied. Is there a Trojan? I use the fport.exe to query the port and find that there is no program at all. What is the reason? Fortunately, I can start debugging, I track the start () function of the CassiniWorm class of CassiniWebserver.cs, found that errors occur at the following code
Try {
_Server = new cassini.server (portnumber, _virtroot, _apppath);
_Server.Start ();
}
Catch {
SHOWERROR
"Cassini Managed Web Server Failed to Start Listening On Port" Portnumber "./R/N"
"Possible Conflict With Another Web Server on The Same Port.");
PortTextBox.selectall ();
PortTextBox.focus ();
Return;
} Is also an error when you create a Server.
But unfavorable is that the source code does not give an error reason, but the arbitrarily tells me "Cassini Managed Web Server Failed to Start Listening on Port XXX", it is obviously unclear (estimated author's can't catch the exception.).
In order to understand the reasons, I joined
Catch (Exception E) {
Messagebox.show (e.tostring ());
......
In this way, an error prompt is displayed. It turns out that the assembly you need to use in the ASP.NET creation application field is in a private directory or GAC. After the previous installation, see the .snk certificate file is to sign the signed and copy to the global DLL. But I didn't do this, so the CLR will find the assembly of the required assembly in the subdirectory bin / under the current directory of the process. And I will originally a source of the two assembly to an assembly, causing the search assembly to fail. Until the reason, establish a bin directory, and copy the compiled EXE file to the bin directory of the execution starting point of the ASP.NET, the system starts OK.3, test, through the IE test, found everything, it seems to run under IIS same.
(to be continued)