Implement a small IIS program that supports the host Asp.net Program (cassinidev Introduction)

Source: Internet
Author: User
Introduction

A system designed for customers based on the traditional C/S architecture (WPF + WCF). Later, the customer wrote some Web-Based Query gadgets as needed, after the development is complete, you will find that IIS is not installed on the server.

The server is a Windows 2003 Server Operating System, and the backup of the system installation file is not retained on the hard disk. To install IIS, you have to run the data center for laziness.ProgramClerk, he began to find a way to find a poor path.

Google, get the following information:

    • Cassini-- Vs comes with ASP. NET development server predecessor (http://blogs.msdn.com/ B /dmitryr/), but unfortunately this thing only supports local connection, and the maximum only support to. NET Framework 3.5, pass off.
    • IIS Express-- Microsoft intends to replace ASP. net Development Server tool, not only supports remote connection ,. NET framework 4 is even more powerful than the server provided by vs. I believe many vs web developers have replaced the Asp.net development server provided by Vs with IIS Express, however, for a newbie to my web, this item is still heavyweight, and configuration is troublesome. I am too lazy to study it and pass it off.
    • Cassinidev --Is the main character of this article, this is an open source project (http://cassinidev.codeplex.com/), support remote connection, support. Net 3.5 and 4.0, can be source code reuse or assembly reuse, absolutely lightweight, easy to deploy.
Example

Download:

Cassinidev 3.5.1.8-4.1.0.8 release (Official download)

The downloaded package contains many EXE and DLL files. The following describes the functions of each file:

Directly used:

Cassinidev.exe: corresponds to. NET Framework 3.5, Asp.net 2.0, windowform Gui

Cassinidev4.exe: corresponds to. NET Framework 4, Asp.net 4.0, windowform Gui

CassiniDev-console.exe: corresponds to. NET Framework 3.5, Asp.net 2.0, console Program

CassiniDev4-console.exe: corresponds to. NET Framework 4, Asp.net 4.0, console Program

For secondary development:

CassiniDev-lib.dll: corresponds to. NET Framework 3.5, Asp.net 2.0

CassiniDev4-lib.dll: corresponds to. NET Framework 4, Asp.net 4.0

For vs debugging (that is, to replace ASP. NET development server that comes with ):

Webdev.webserver.exe

Webdev.webserver20.exe

Webdev.webserver40.exe

Usage:

In general, the above EXE can be used directly to implement Asp.net boarding, but the corresponding, for our control is relatively small, not free, for example, in actual applications, we may need to write our host as a Windows service, so we can't implement it directly using the above exe. In this case, we can use cassinidev-Lib for secondary development, or even directly download it from the official website.Source codeTo generate the program you need, the following is a simple example, using the cassinidve4-lib.dll to achieve a Asp.net host

Create a WPF Application in vs2010, add a textbox in the main window to display information, and modify mainwindow.CodeAs follows:

 
UsingSystem;
 
UsingSystem. Collections. Generic;
 
UsingSystem. LINQ;
 
UsingSystem. text;
 
UsingSystem. windows;
 
UsingSystem. Windows. controls;
UsingSystem. Windows. Data;
 
UsingSystem. Windows. documents;
 
UsingSystem. Windows. input;
 
UsingSystem. Windows. Media;
 
UsingSystem. Windows. Media. imaging;
 
UsingSystem. Windows. Navigation;
 
UsingSystem. Windows. shapes;
 
UsingCassinidev;
 
 
 
NamespaceJkaspnethost
 
{
 
/// <Summary>
/// Interaction logic of mainwindow. XAML
 
/// </Summary>
 
Public Partial ClassMainwindow: Window
 
{
 
Private ReadonlyServer server;
 
 
 
PublicMainwindow ()
 
{
 
Initializecomponent ();
 
 
Server =NewServer (8038,"/", System. Io. Path. Combine (appdomain. currentdomain. basedirectory,"Webapp"),
 
System. net. IPaddress. parse ("0.0.0.0"),"", 0,False,False);
 
 
 
Server. Start ();
 
Textlog. appendtext ("The server is running... \ r \ n");
 
Textlog. appendtext (server. physicalpath +"\ R \ n");
 
Textlog. appendtext (server. rooturl +"\ R \ n");
Server. requestcomplete + =NewEventhandler <requesteventargs> (server_requestcomplete );
 
}
 
 
 
VoidServer_requestcomplete (ObjectSender, requesteventargs E)
 
{
 
// It may be called by a thread other than the UI thread, so dispatcher. Invoke is required.
 
Dispatcher. Invoke (NewAction () => {
 
Textlog. appendtext ("Request :"+ E. requestlog. url +"\ R \ n");
 
If(Textlog. Text. Length & gt; 10000)
 
{
Textlog. Text = textlog. Text. substring (textlog. Text. Length-1000,100 0 );
 
}
 
Textlog. scrolltoend ();
 
}));
 
}
 
 
 
Private VoidWindow_closing (ObjectSender, system. componentmodel. canceleventargs E)
 
{
 
Try
 
{
 
Server. Shutdown ();
 
}
 
Catch{}
 
}
 
}
 
}

 

Other Purposes

1. If you need to make some demo programs or introduction programs that come with the CD, but have no experience in developing desktop applications, you can use cassinidev + webbrowser. In the same EXE, it is both a server and a front-end presentation layer and can be used out of the box without installation.

2. Stand-alone applications or small LAN applications. using powerful HTML as the presentation layer, the user experience is no worse than the traditional MFC, windowfrom, development efficiency, and beautiful interface.

3 ,...

Original article: http://www.cnblogs.com/sweethome/archive/2011/09/22/2184988.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.