新聞中心
《在openSUSE下ASP.NET 4開發(fā)環(huán)境配置》中已經(jīng)配置好了 openSUSE 11.3 操作系統(tǒng)。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),衡南企業(yè)網(wǎng)站建設(shè),衡南品牌網(wǎng)站建設(shè),網(wǎng)站定制,衡南網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,衡南網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
現(xiàn)在,我們進(jìn)入“GNOME 終端”,使用 ifconfig 命令驗證一下本虛擬的 IP 地址就是一開始我們在寬帶路由器中為它分配的靜態(tài)地址。
- ben@linux-nyhn:~> /sbin/ifconfig
- eth0 Link encap:Ethernet HWaddr 08:00:27:51:5B:0B
- inet addr:192.168.1.251 Bcast:192.168.1.255 Mask:255.255.255.0
- inet6 addr: fe80::a00:27ff:fe51:5b0b/64 Scope:Link
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:853 errors:0 dropped:0 overruns:0 frame:0
- TX packets:807 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:853227 (833.2 Kb) TX bytes:90376 (88.2 Kb)
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- inet6 addr: ::1/128 Scope:Host
- UP LOOPBACK RUNNING MTU:16436 Metric:1
- RX packets:22 errors:0 dropped:0 overruns:0 frame:0
- TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:1300 (1.2 Kb) TX bytes:1300 (1.2 Kb)
- ben@linux-nyhn:~> sudo vim /etc/hosts
如上所示,再使用 vim 編輯器編輯 /etc/hosts 文件,增加一個域名 ben.skyiv.com,如下圖所示:
注意上圖中的 IP 地址必須是 127.0.0.1,而不能是 192.168.1.251。在宿主機(jī)的 Windows Vista 操作系統(tǒng)中以管理員身份進(jìn)入命令提示符,使用記事本編輯 C:\Windows\System32\drivers\etc\hosts 文件,增加一個同樣的域名 ben.skyiv.com,注意此時 IP 地址必須是 192.168.1.251,而不能是 127.0.0.1,如下圖所示:
我們的 openSUSE 11.3 操作系統(tǒng)已經(jīng)安裝好了 apache 軟件,但尚未啟用,如下所示:
- ben@linux-nyhn:~> sudo /sbin/service apache2 status
- Checking for httpd2: unused
那么,現(xiàn)在,讓我們設(shè)置 apache 為開機(jī)隨系統(tǒng)啟動,并且現(xiàn)在就啟動它吧:
- ben@linux-nyhn:~> sudo /sbin/chkconfig -add apache2
- apache2 0:off 1:off 2:off 3:on 4:off 5:on 6:off
- ben@linux-nyhn:~> sudo /sbin/service apache2 start
- Starting httpd2 (prefork) done
- ben@linux-nyhn:~> sudo /sbin/service apache2 status
- Checking for httpd2: running
現(xiàn)在讓我們在宿主機(jī)的 Windows Vista 操作系統(tǒng)的谷歌瀏覽器中打開 ben.skyiv.com 網(wǎng)站試試看吧:
如上圖所示,我們的 Apache 2.2.15 已經(jīng)正常工作在 Linux/SUSE 操作系統(tǒng)上了。只不過現(xiàn)在該網(wǎng)站還沒有內(nèi)容而已。
在 openSUSE 操作系統(tǒng)中,Apache 的默認(rèn)文檔是放在 /srv/www/htdocs 目錄下的。
openSUSE 操作系統(tǒng)已經(jīng)為每個用戶建立了 public_html 目錄,例如我的用戶就是 /home/ben/public_html 目錄,用以放置該用戶的網(wǎng)站的內(nèi)容??梢酝ㄟ^ ben.skyiv.com/~ben 訪問,這里 ben 是我的用戶名,如下圖所示:
從上圖中可以看出,這個目錄是空的,需要用戶自己放里放東東。那么,我們就編寫如下一個 index.html 吧:
- ben@linux-nyhn:~> cd public_html
- ben@linux-nyhn:~/public_html> vim index.html
再次在 Windows Vista 操作系統(tǒng)中訪問 ben.skyiv.com/~ben 網(wǎng)頁:
現(xiàn)在讓我們來看看 mono 的版本:
- ben@linux-nyhn:~> mono --version
- Mono JIT compiler version 2.6.4 (tarball Mon Jul 5 13:53:45 UTC 2010)
- Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
- TLS: __thread
- GC: Included Boehm (with typed GC and Parallel Mark)
- SIGSEGV: altstack
- Notifications: epoll
- Architecture: amd64
- Disabled: none
- ben@linux-nyhn:~>
- ben@linux-nyhn:~> gmcs --version
- Mono C# compiler version 2.6.4.0
這個 mono 2.6.4 的版本太低了。根據(jù) mono 官方下載頁面的指示,按如下步驟進(jìn)行升級:
- ben@linux-nyhn:~> sudo zypper addrepo http://ftp.novell.com/pub/mono/download-stable/openSUSE_11.3 mono-stable
- 正在添加安裝源 'mono-stable' [done]
- Repository 'mono-stable' successfully added
- Enabled: Yes
- Autorefresh: No
- URI: http://ftp.novell.com/pub/mono/download-stable/openSUSE_11.3
- ben@linux-nyhn:~> sudo zypper refresh --repo mono-stable
- Retrieving repository 'mono-stable' metadata [done]
- 正在構(gòu)建 'mono-stable' 安裝源緩存 [done]
- Specified repositories have been refreshed.
- ben@linux-nyhn:~> zypper dist-upgrade --repo mono-stable
- =================> 在這里進(jìn)行漫長的升級 <=================
- ben@linux-nyhn:~>
升級完成,再次查看 mono 的版本:
- ben@linux-nyhn:~> mono --version
- Mono JIT compiler version 2.8.1 (tarball Fri Nov 12 14:37:21 UTC 2010)
- Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
- TLS: __thread
- SIGSEGV: altstack
- Notifications: epoll
- Architecture: amd64
- Disabled: none
- Misc: debugger softdebug
- LLVM: yes(2.8svn-mono)
- GC: Included Boehm (with typed GC and Parallel Mark)
- ben@linux-nyhn:~> dmcs --version
- Mono C# compiler version 2.8.1.0
果然已經(jīng)升級到最新的 mono 2.8.1 版本了。
在 Apache mod_mono configuration tool 網(wǎng)頁可以生成運行 ASP.NET 所需要的 Apache 軟件的配置文件,如下圖所示:
生成的 ben.skyiv.com.conf 文件如下所示:
- ServerName ben.skyiv.com
- DocumentRoot /home/ben/www
- # MonoServerPath can be changed to specify which version of ASP.NET is hosted
- # mod-mono-server1 = ASP.NET 1.1 / mod-mono-server2 = ASP.NET 2.0
- # For SUSE Linux Enterprise Mono Extension, uncomment the line below:
- # MonoServerPath ben.skyiv.com "/opt/novell/mono/bin/mod-mono-server2"
- # For Mono on openSUSE, uncomment the line below instead:
- MonoServerPath ben.skyiv.com "/usr/bin/mod-mono-server2"
- # To obtain line numbers in stack traces you need to do two things:
- # 1) Enable Debug code generation in your page by using the Debug="true"
- # page directive, or by setting in the
- # application's Web.config
- # 2) Uncomment the MonoDebug true directive below to enable mod_mono debugging
- MonoDebug ben.skyiv.com true
- # The MONO_IOMAP environment variable can be configured to provide platform abstraction
- # for file access in Linux. Valid values for MONO_IOMAP are:
- # case
- # drive
- # all
- # Uncomment the line below to alter file access behavior for the configured application
- MonoSetEnv ben.skyiv.com MONO_IOMAP=all
- #
- # Additional environtment variables can be set for this server instance using
- # the MonoSetEnv directive. MonoSetEnv takes a string of 'name=value' pairs
- # separated by semicolons. For instance, to enable platform abstraction *and*
- # use Mono's old regular expression interpreter (which is slower, but has a
- # shorter setup time), uncomment the line below instead:
- # MonoSetEnv ben.skyiv.com MONO_IOMAP=all;MONO_OLD_RX=1
- MonoApplications ben.skyiv.com "/:/home/ben/www"
- Allow from all
- Order allow,deny
- MonoSetServerAlias ben.skyiv.com
- SetHandler mono
- SetOutputFilter DEFLATE
- SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
- AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
這個 ben.skyiv.com.conf 文件需要放在 /etc/apache2/conf.d 目錄下:
- ben@ben:~> ll /etc/apache2/conf.d
- 總計 8
- -rw-r--r-- 1 ben users 2037 01-04 01:21 ben.skyiv.com.conf
- -rw-r--r-- 1 root root 1239 10-01 02:12 mod_mono.conf
然后創(chuàng)建 /home/ben/www 目錄,并重啟 Apache 服務(wù):
- ben@ben:~> mkdir www
- ben@ben:~> sudo /etc/init.d/apache2 restart
- Syntax OK
- Shutting down httpd2 (waiting for all children to terminate) done
- Starting httpd2 (prefork) done
- ben@ben:~>
現(xiàn)在讓我們建立一個網(wǎng)站:
- ben@ben:~> cd www
- ben@ben:~/www> vim index.html
在 openSUSE 11.3 操作系統(tǒng)中訪問 ben.skyiv.com 網(wǎng)站,如下圖所示:
點擊上圖中的“服務(wù)器信息”,出現(xiàn)“The resource cannot be found”錯誤:
這是預(yù)料之中的,因為我們還沒有編寫 info.aspx 文件呢。從上圖中可以看出,ASP.NET 是 2.0 版的。
現(xiàn)在,我們修改 /etc/apache2/conf.d/ben.skyiv.com.conf 文件,如下所示:
- ben@ben:~/www> sudo vim /etc/apache2/conf.d/ben.skyiv.com.conf
如上圖所示,將 mod-mono-server2 改為 mod-mono-server4 。然后重啟 Apache 服務(wù):
- ben@ben:~> sudo /etc/init.d/apache2 restart
- Syntax OK
- Shutting down httpd2 (waiting for all children to terminate) done
- Starting httpd2 (prefork) done
- ben@ben:~>
然后重新訪問 ben.skyiv.com/aspx/info.aspx 網(wǎng)頁:
從上圖中可以看出,已經(jīng)運行在 ASP.NET 4 了。
現(xiàn)在,讓我們來編寫 info.aspx 程序吧:
- ben@linux-nyhn:~/www> mkdir aspx src bin
- ben@linux-nyhn:~/www> vim aspx/info.aspx
- ben@linux-nyhn:~/www> vim src/info.aspx.cs
- ben@linux-nyhn:~/www> vim src/info.rsp
網(wǎng)頁文件 aspx/info.aspx 的內(nèi)容如下所示:
- <%@ Page Language="C#" inherits="Skyiv.Ben.Web.InfoPage" %>
服務(wù)器信息 - 返回
對應(yīng)的 C# 源程序 src/info.aspx.cs 的內(nèi)容如下所示:
- using System;
- using System.Data;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace Skyiv.Ben.Web
- {
- public class InfoPage : Page
- {
- protected GridView dgMain;
- public void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack) return;
- dgMain.DataSource = GetInfo();
- dgMain.DataBind();
- }
- DataTable GetInfo()
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("項目", typeof(string));
- dt.Columns.Add("內(nèi)容", typeof(string));
- AddRow(dt, "操作系統(tǒng)", Environment.OSVersion);
- AddRow(dt, "公共語言運行庫", Environment.Version);
- return dt;
- }
- void AddRow(DataTable dt, string name, object value)
- {
- DataRow dr = dt.NewRow();
- dr[0] = name;
- dr[1] = value.ToString();
- dt.Rows.Add(dr);
- }
- }
- }
編譯響應(yīng)文件 src/info.rsp 的內(nèi)容如下所示:
- -out:../bin/info.dll
- -t:library
- -r:System.Data
- -r:System.Web
- info.aspx.cs
然后就是使用以下命令進(jìn)行編譯了:
- ben@linux-nyhn:~/www> cd src
- ben@linux-nyhn:~/www/src> dmcs @info.rsp
編譯完成,網(wǎng)站的運行效果如下圖所示:
至此,我們成功地在 Linux 操作系統(tǒng)中運行 ASP.NET 4。
分享標(biāo)題:Linux操作系統(tǒng)中運行ASP.NET4
本文鏈接:http://fisionsoft.com.cn/article/coseoss.html


咨詢
建站咨詢
