Ull*_*lla 5 .net apache asp.net mono mod-mono
我想使用IHttpHandler方法在.Net-Project中使用XSP或更好的mod_mono.
我有以下课程(非常简单:
public class Class1 : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
var result = "<h1>Yeah</h1>";
var bytes = Encoding.UTF8.GetBytes(result);
context.Response.Write(result);
}
}
Run Code Online (Sandbox Code Playgroud)
以及web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Execute, Script">
<add name="Class" path="*" verb="*" type="IISHost.Class1" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
<system.web>
<compilation defaultLanguage="c#" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
它在IIS中完美运行.http://127.0.0.1/test/kfdlsa返回'是'
在Apache的XSP或mod_mono中,我可以创建一个index.aspx,它根据.Net-Framework完美地解析和执行,但似乎处理程序不包含在mod_mono-Framework中.
使用IHttpHandler是否真的在Mono中实现,或者我是否应该使用另一种方法来收集对某个主机和/或虚拟目录的所有请求.
Ced*_*edX 11
HTTP处理程序和模块在Mono中运行良好.
您的问题是您的Web.config文件使用特定于IIS的"集成管道"模式的语法.Apache/mod_mono下不存在此模式.因此,您必须使用旧语法(即"经典管道"模式的语法)并提供<system.web/httpHandlers>除现有<system.webServer/handlers>部分之外的部分.
看这个Web.config例子:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*.rss" verb="*" type="CedricBelin.Web.FeedHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="Feed" path="*.rss" verb="*" type="CedricBelin.Web.FeedHandler" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
该<validation ...>标签是非常重要的:如果你忘记它,IIS会抛出一个错误,抱怨未经授权的部分在综合管线上下文中使用.
下一步是指示Apache服务器将文件的处理转移到mod_mono,如下所示:
<VirtualHost *:80>
ServerName mono.localhost
DocumentRoot "/Library/WebServer/Documents/MonoTest"
AddType application/x-asp-net .rss
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这条线AddType application/x-asp-net .rss很重要.请参阅此行中的path="*.rss"in Web.config和.rssextension 之间的关系.如果你想处理所有的扩展,因为在你的榜样(path="*"),则必须更换线AddType application/x-asp-net .rss通过ForceType application/x-asp-net.
| 归档时间: |
|
| 查看次数: |
2247 次 |
| 最近记录: |