添加自定义IIS处理程序

问题描述 投票:-1回答:1

我在为IIS创建新处理程序(我尝试过的第一个处理程序时遇到问题。我的设置是:

Windows Server 2012上的IISWindows 10上的Visual Studio 2017(当前正在运行php网站)

这是mt处理程序的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ProvaIISdotNET
{
    class myHandler : IHttpHandler
    {
        #region IHttpHandler Members
        public bool IsReusable {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {

            context.Response.Write("<html><body>Hi everybody!</body></html>");
        }

        #endregion
    }

}

在Visual Studio上,我做了一个新的可视C#项目>类库(.Net Framework)

  1. 将System.web添加到参考文献中
  2. 编译了.NET 4的代码(发行版)
  3. 复制了inetpub \ mysite \ bin中的dll文件
  4. 将映射路径添加到test.test,测试为'name'
  5. 在处理程序映射中>添加托管处理程序,我找不到“ myHandler”类型,即使将其手动添加到mysite / test.test页面也找不到404。

我想念什么?

c# .net iis handler
1个回答
0
投票

这就是我部署处理程序的方式。1.创建一个名为“ ProvaIISdotNET”的组装项目。

2。我删除默认的class.cs并创建了myHandler.cs

3。我复制了这样的代码。由于VS发出了system.linq的警报,因此在这里不需要它,因此我将其删除。

using System;
using System.Collections.Generic;

using System.Text;
using System.Web;

namespace ProvaIISdotNET
{
    class myHandler : IHttpHandler
    {
        #region IHttpHandler Members
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {

            context.Response.Write("<html><body>Hi everybody!</body></html>");
        }

        #endregion
    }

}
  1. 我将发行版.dll复制到我站点的根bin文件夹D:\ mysite \ bin(请确保将程序集放在根bin文件夹中]]] >>

  2. 我将此添加到根web.config system.webserver \ handlers部分。请确保在type属性的末尾没有空格“”。

     <handlers>
            <add name="myhandler" path="*" verb="GET" type="ProvaIISdotNET.myHandler" />
        </handlers>
    
  3. 6。我回收了应用程序池。

    现在它在我这边工作

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.