在FreeBSD上边使用.net环境

最近有需要在FreeBSD上边运行.net的web环境,早以久仰mono大名,如是去到它的官网(http://mono-project.com/)大致的研究了一下.
也动手尝试了一下,还好比较简单,做笔记如下:

首先在FreeBSD上边安装Apache:

cd /usr/ports/www/apache22
make install clean

然后再安装mono:

cd /usr/ports/lang/mono
make install clean

再安装mod_mono:

cd /usr/ports/www/mod_mono
make install clean

网上有些资料说还要安装xsp,但这个时候用pkg_info查看的时候,其实xsp已经装上了.

现在就是对mono进行配置,使apache支持它.
使用port安装mod_mono的时候,会自动在:
/usr/local/etc/apache22/Includes
位置生成mod_mono.conf文件,它的内容是:

more /usr/local/etc/apache22/Includes/mod_mono.conf
# mod_mono.conf

# Achtung! This file may be overwritten
# Use ‘include mod_mono.conf’ from other configuration file
# to load mod_mono module.
LoadModule mono_module /usr/local/libexec/apache22/mod_mono.so
Header set X-Powered-By “Mono”

AddType application/x-asp-net .aspx
AddType application/x-asp-net .asmx
AddType application/x-asp-net .ashx
AddType application/x-asp-net .asax
AddType application/x-asp-net .ascx
AddType application/x-asp-net .soap
AddType application/x-asp-net .rem
AddType application/x-asp-net .axd
AddType application/x-asp-net .cs
AddType application/x-asp-net .vb
AddType application/x-asp-net .master
AddType application/x-asp-net .sitemap
AddType application/x-asp-net .resources
AddType application/x-asp-net .skin
AddType application/x-asp-net .browser
AddType application/x-asp-net .webinfo
AddType application/x-asp-net .resx
AddType application/x-asp-net .licx
AddType application/x-asp-net .csproj
AddType application/x-asp-net .vbproj
AddType application/x-asp-net .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.aspx

在apache配置文件httpd.conf中加入如下内容:

Include /usr/local/etc/apache22/Includes/mod_mono.conf

好,所有的配置完成.现在做一个测试页面来测试一下.

ee /usr/local/www/apache22/data/test.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void  Page_Load(object sender, EventArgs e)
{
    Response.Write("<center><h1>Hello world~</h1><br />Hello mono~</center>");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>test page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>

后用浏览器打开看看,如果显示:
Hello Service Labs~
Hello itkylin.com~

嗯,那就是配置成功了.