【转】Apache + ASP.NET

一、简要说明

1、安装所用到的软件:

apache_2.0.55-win32-x86-no_ssl.msi

http://archive.apache.org/dist/httpd/binaries/win32/apache_2.0.55-win32-x86-no_ssl.msi

mod_aspdotnet-2.0.0.msi

http://archive.apache.org/dist/httpd/mod_aspdotnet/mod_aspdotnet-2.0.0.msi

dotNetFramework1.1

http://download.microsoft.com/download/7/b/9/7b90644d-1af0-42b9-b76d-a2770319a568/dotnetfx.exe

2、mod_aspdotnet说明:mod_aspdotnet 是Apache基金会一个已经停止的项目,该项目以模块方式为Apache Web 服务器提供对微软 ASP.NET 应用支持。我们下载到的mod_aspdotnet-2.0.0.msi只支持Apache2.0.x。目前该模块配合 .NET Framework v1.0 or V1.1 完整支持 Asp.Net 1.1、试验性支持 Asp.Net 2.0,但不能配合 .NET Framework 2.0 工作。目前,这个mod_aspdotnet模块最大的问题是在认证支持上的不足,比如windows和form都还不能支持

现在新更新了的mod_aspdotnet-2.2.0.2004-snapshot-rev419792.msi提供了针对 Apache 2.2.x 准备的 mod_aspdotnet 模块。

二、安装Apache

下载完Apache后,双击apache_2.0.55-win32-x86-no_ssl.msi文件。选择同 意条款,点Next;在Network Domain的框里填入域名(不带www的),在ServerName填入带前缀的域名(有带www或其他前缀的),在Email Address填入你的Email地址;点选For All Users单选框;然后一路Next。

三、安装.NET Framework

双击dotnetfx.exe,也是一路Next就行了。

四、安装mod_aspdotnet

在安装mod_aspdotnet之前一定要先安装好Apache和.NET Framework。

双击mod_aspdotnet-2.0.0.msi,选择同意条款,点Next;选择All Users单选框,一路Next就行了。

五、配置httpd.conf

进入Apache安装目录下,找到conf文件夹,双击进入。用文本打开httpd.conf文件,在文件的最底部加入:

#加载asp.net模块

LoadModule aspdotnet_module "modules/mod_aspdotnet.so"

#如果mod_aspdotnet加载成功

<IfModule mod_aspdotnet.cpp>

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

              # For all virtual ASP.NET webs, we need the aspnet_client files

              # to serve the client-side helper scripts.

              AliasMatch ^/(?i)aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/WINNT/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"

             

              <Directory "C:/WINNT/Microsoft.NET/Framework/v*/ASP.NETClientFiles">

                            Options FollowSymlinks

                            Order allow,deny

                            Allow from all

              </Directory>

</IfModule>

#如果mod_aspdotnet加载成功

#如果有配置虚拟主机,以下这一块可放到<VirtualHost *:80></VirtualHost>之间的</VirtualHost>之前

              <IfModule mod_aspdotnet.cpp>

                            # 加载 ASP.NET 应用,当第一个参数为“/”时为整个虚拟主机都需要支持asp.net;也可以设置为虚拟目录,只要加上虚拟目录名即可,如AspNetMount /dotnet "D:\Apache\Apache2\htdocs\dotnet"

                            AspNetMount / "$Apache_home\htdocs"

                            # 设置应用asp.net的虚拟目录,当整个虚拟主机都需要支持asp.net时不要设

                            #Alias /dotnet "$Apache_home\htdocs\dotnet"

                            # 允许 asp.net scripts 执行以下目录

                            <Directory "$Apache_home\htdocs">

                                          Options FollowSymlinks ExecCGI

                                          Order allow,deny

                                          Allow from all

                            </Directory>

              </IfModule>

这个设置是没有配置虚拟主机的设置,Apache默认的主机根目录是htdocs,你在应用中要把$Apache_home改成Apache安装目录。

六、测试

在主机根目录中加添加个HelloWorld文件,测试一下:

HelloWorld.aspx:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml"; >

<head runat="server">

    <title>Hello World! - mod_aspdotnet</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <% Response.Write("<h1>Hello World!</h1>")%>

    </div>

    </form>

</body>

</html>

打开浏览器,在地址栏输入:http://127.0.0.1/HelloWorld.aspx

如果正确输出Hello World!

说明你的配置是正确的,现在你可以在Apache中使用ASP.Net了。

七、注意:由于apache本身对于url的目录和文件名是大小写敏感的,所以asp.net的虚拟目录必须要注 意大小写,否则访问的时候不会出错,不过将会找不到任何的文件,就像访问一个空的目录一样。除了虚拟目录名外,由于其它的aspx文件是 mod_aspdotnet模块载入的,所以又仍然是非大小写敏感的。

#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 example application

AspNetMount /szwqxh "E:/xampp/htdocs/dotnet/szwqxh"

# Map all requests for /active to the application files

Alias /szwqxh "E:/xampp/htdocs/dotnet/szwqxh"

# Allow asp.net scripts to be executed in the active example

<Directory "E:/xampp/htdocs/dotnet/szwqxh">

#ExecCGI

Options FollowSymlinks

Order allow,deny

Allow from all

DirectoryIndex Default.aspx

</Directory>

<Directory "E:/xampp/htdocs/dotnet/t">

Options FollowSymlinks ExecCGI

Order allow,deny

Allow from all

DirectoryIndex Default.aspx

</Directory>

# For all virtual ASP.NET webs, we need the aspnet_client files

# to serve the client-side helper scripts.

AliasMatch ^/(?i)aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "D:/WINDOWS/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"

<Directory "D:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles">

Options FollowSymlinks ExecCGI

Order allow,deny

Allow from all

</Directory>

</IfModule>

<VirtualHost 192.168.0.100:80>

##    ServerAdmin webmaster@szwqxh.com

##    DocumentRoot E:/xampp/htdocs/dotnet/szwqxh

##    ServerName szwqxh.com

##    ServerAlias www.szwqxh.com

    ## ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log

    ## CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common

    #如果mod_aspdotnet加载成功

    #如果有配置虚拟主机,以下这一块可放到<VirtualHost *:80></VirtualHost>之间的</VirtualHost>之前

    <IfModule mod_aspdotnet.cpp>

                  # 加载 ASP.NET 应用,当第一个参数为“/”时为整个虚拟主机都需要支持asp.net;也可以设置为虚拟目录,只要加上虚拟目录名即可,如AspNetMount /dotnet "D:\Apache\Apache2\htdocs\dotnet"

                  AspNetMount / "$Apache_home\htdocs"

                  # 设置应用asp.net的虚拟目录,当整个虚拟主机都需要支持asp.net时不要设

                  #Alias /dotnet "$Apache_home\htdocs\dotnet"

                  # 允许 asp.net scripts 执行以下目录

                  <Directory "$Apache_home\htdocs">

                                Options FollowSymlinks ExecCGI

                                Order allow,deny

                                Allow from all

                  </Directory>

    </IfModule>

</VirtualHost>

原文地址:https://www.cnblogs.com/alphaqiu/p/2346431.html