试用mono( 三)新建Web应用篇

今天我介绍mono的三个部分:ASP.Net项目。Mono上的ASP.Net Web应用可以有两种方式运行,第一种是apache+mono module的方式,第二种是xsp standalone的方式。我用的是第二种,xsp是一个用C#写的简单(或者说轻量级>也可)的web服务器,用于运行ASP.NET 1.1和2.0的程序。

在的mono版本已经完全实现了ASP.NET的所有功能,也就是说,你在windows下写的ASP.NET程序在linux下的mono下也可以运行。当然这里的“linux”只不过是强调一下,作为一个轻>量级的C# Server,xsp也可以在windows下运行的。

我们开始吧,首先选择File -> New Project… -> C# -> ASP.NET -> Web Application。这样,mono会生成一个简单的ASP.NET程序,Default页面中带有一个TextBox和一个Button>。我们进行扩展一下。

ASP.NET Dev

左面的Solution工具栏中双击Default.aspx,这时出现Default.aspx的前端代码。我们添加一个Label,同时把页面修改一下,加一些标题和分割符。如下:

Default

This is an ASP.Net Web application test on mono

Solution工具栏中双击Default.aspx里面的Inherits Default in Default.aspx.cs,这>时出现了Default.aspx的后端处理代码,我们添加一个控件Label,并修改一下事件代码:

using System;
using System.Web;
using System.Web.UI;
namespace local1
{
public class Default : Page
{
protected System.Web.UI.HtmlControls.HtmlForm form1;
protected System.Web.UI.WebControls.TextBox textBox1;
protected System.Web.UI.WebControls.Button button1;
protected System.Web.UI.WebControls.Label label1;
public virtual void onButtonClick(object sender, EventArgs e)
{
this.label1.Text = “Welcome : ” + textBox1.Text + ““;
}
}
}

ASP.NET Web Page

编译F5,之后浏览器会出现一个Default.aspx的页面。我们文本框中输入一个字符串,点击按钮,label显示欢迎字符串,如上图所示。

Leave a Reply

Your email address will not be published. Required fields are marked *