加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Mono和IHttpHandler

发布时间:2020-12-16 03:37:32 所属栏目:asp.Net 来源:网络整理
导读:我想使用IHttpHandler方法在.Net-Project中使用XSP或更好的mod_mono. 我有以下课程(非常简单: public class Class1 : IHttpHandler{ public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { var result = "h
我想使用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);
    }
}

以及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>

它在IIS中完美运行. http://127.0.0.1/test/kfdlsa返回’是’

在Apache的XSP或mod_mono中,我可以创建一个index.aspx,它根据.Net-Framework完美地解析和执行,但似乎处理程序不包含在mod_mono-Framework中.

使用IHttpHandler是否真的在Mono中实现,或者我是否应该使用另一种方法来收集对某个主机和/或虚拟目录的所有请求.

解决方法

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>

<验证...>标记非常重要:如果您忘记了它,IIS会抛出错误并抱怨在Integrated Pipeline上下文中使用了未经授权的部分.

下一步是指示Apache服务器将文件的处理转移到mod_mono,如下所示:

<VirtualHost *:80>
    ServerName mono.localhost
    DocumentRoot "/Library/WebServer/Documents/MonoTest"
    AddType application/x-asp-net .rss
</VirtualHost>

AddType application / x-asp-net .rss这一行很重要.请参阅Web.config中的path =“*.rss”与此行中的.rss扩展名之间的关系.如果要处理所有扩展(如示例(path =“*”)),则必须使用ForceType application / x-asp-net替换AddType application / x-asp-net .rss行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读