2010年9月7日 星期二

如何在XAMPP下加裝ASP.NET模組

測試平台 XAMPP 2.5, Apache 2.2.9。

安裝模組為mod_aspdotnet-2.2.0.2006-setup-r2.msi
根據[2]指出,要依不同的apache版本選用不同的安裝程式
[1]應該是原始出處,安裝前需安裝Microsoft .NET Framework 2.0[2]中提到建議用Mircosoft .NET Framework 3.5以上。筆者實測結果,.NET 4.0 無法安裝,.NET 2.0 可正常運作。

一開始安裝時,可能要搜尋apache所在的位置,遇到無回應似當掉的情形,須耐心等待。

安裝後,修改apache/conf/httpd.conf
在最後端加入下列資訊

#asp.net
LoadModule aspdotnet_module "modules/mod_aspdotnet.so"

AddHandler asp.net asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo

<IfModule mod_aspdotnet.cpp>
# Mount the ASP.NET /asp application
AspNetMount /SampleASP "c:/SampleASP"
#/SampleASP is the alias name for asp.net to execute
#"c:/SampleASP" is the actual execution of files/folders in that location

# Map all requests for /asp to the application files
Alias /SampleASP "c:/SampleASP"
#maps /SampleASP request to "c:/SampleASP"
#now to get to the /SampleASP type http://localhost/SampleASP
#It'll redirect http://localhost/SampleASP to "c:/SampleASP"

# Allow asp.net scripts to be executed in the /SampleASP example
<Directory "c:/SampleASP">
Options FollowSymlinks ExecCGI
Order allow,deny
Allow from all
DirectoryIndex index.htm index.aspx
#default the index page to .htm and .aspx
</Directory>

# For all virtual ASP.NET webs, we need the aspnet_client files
# to serve the client-side helper scripts.
AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"
<Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles">
Options FollowSymlinks
Order allow,deny
Allow from all
</Directory>
</IfModule>
#asp.net

/SampleASP 可換成自訂的別名
c:/SampleASP 可換成自訂的路徑
重新啟動apache,將範例程式存成.aspx放到路徑資料夾中,開啟瀏覽器測試即可。
ASP.NET範例程式:

<%@ Page Language="VB" %>
<html>
<head>
<link rel="stylesheet"href="intro.css">
</head>
<body>
<center>
<form action="index.aspx" method="post">
<h3> Name: <input id="Name" type=text>
Category: <select id="Category" size=1>
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</h3>
<input type=submit value="Lookup">
<p>
<% Dim I As Integer
For I = 0 to 7 %>
<font size="<%=I%>"> Sample ASP.NET TEST</font> <br>
<% Next %>
</form>
</center>
</body>
</html>

附注:
ASP與ASP.NET不是相同的東西,XAMPP目前沒有提供原生ASP的環境模組[6],Apache::ASP用途是將ASP語法轉為Perl語法。
Reference:
[1] How to make Apache run ASP.NET / ASP.NET 2.0 - Ohad's Blog
[2] Matttt的空間: Apache運行asp.net
[3] 倍星資訊工作室 's Blog - AppServ 跑asp
[4] Summary of mod-aspdotnet on SourceForge
[5] 如何在Apache上執行 ASP.NET之安裝教學 @ 羽澈.Net :: Xuite日誌
[6] Do Microsoft Activer Server Pages (ASP) work with XAMPP?

沒有留言: