简体   繁体   English

IIS 错误 500.2 -1 如何在 IIS Windows 10 中部署一个简单的自定义处理程序?

[英]IIS Error 500.2 -1 How do I deploy a simple custom Handler in IIS Windows 10?

I am trying to teach myself an IIS handler on Windows 10, IIS 10. Naturally, I started with a tutorial我正在尝试在 Windows 10、IIS 10 上自学 IIS 处理程序。当然,我从教程开始

MS Tutorial 硕士教程

It's old, but I can find nothing newer that is this comprehensive, and has the information gathered into one place.它很旧,但我找不到比这更全面的东西了,而且信息集中在一个地方。

The simple class and function is this:简单的 class 和 function 是这样的:

using System;
using System.Web;
namespace IISHandler {
class MyHandler : IHttpHandler {
    public bool IsReusable
    {
        get { return true; }
    }
    public void ProcessRequest(HttpContext context) {
        DateTime dt;
        String useUTC = context.Request.QueryString["utc"];
        if (!String.IsNullOrEmpty(useUTC) &&
            useUTC.Equals("true")) {
            dt = DateTime.UtcNow;
        } else {
            dt = DateTime.Now;
        }
        context.Response.Write(
            String.Format("<h1>{0}</h1>", dt.ToLongTimeString()));

    }
 }
}

I created the assembly in VS 2015, and everything looks fine.我在 VS 2015 中创建了程序集,一切看起来都很好。 Until I tried to "deploy" it.直到我试图“部署”它。 Then everything falls apart.然后一切都崩溃了。

I've been digging for three days now.我已经挖了三天了。 None of the information is in a single place.没有任何信息在一个地方。 I will cover what I have done.我将介绍我所做的。 First thing, is to copy the DLL into the /bin folder of the web application.首先,将 DLL 复制到 web 应用程序的 /bin 文件夹中。 That's fine.没关系。

Then Use the "Add Module" option in IIS Manager.然后使用 IIS 管理器中的“添加模块”选项。 Well, at the default level it gave me this:好吧,在默认级别它给了我这个: 添加到 GAC

Okay, I'm not adding this to the General assembly.好的,我不会将此添加到大会。 All I want is a custom handler in my Web App.我想要的只是我的 Web 应用程序中的自定义处理程序。

Next, paying closer attention, I am adding it only to one Web App.接下来,仔细观察,我只将它添加到一个 Web 应用程序中。

The tutorial says that the Add Module will discover it.该教程说添加模块会发现它。 Well, that didn't happen.好吧,那没有发生。 I've got a list of things that appear to be "Built in", but not the DLL I created from the tutorial.我有一个似乎是“内置”的东西的列表,但不是我从教程中创建的 DLL。

模块列表

So I manually just typed in the name "IISHandler.MyHandler", which is the namespace (assembly) and the class name.所以我手动输入名称“IISHandler.MyHandler”,即命名空间(程序集)和 class 名称。 Then IIS Manager tells me this:然后 IIS 经理告诉我这个:

添加失败

No amount of web searching has given me any clue how to deal with it.没有多少 web 搜索给我任何线索如何处理它。

Next up, I decided to dig into the web.config file.接下来,我决定深入研究 web.config 文件。 Of course the MS page tells you that you can get all the detailed information... sometime in the future.当然,MS 页面会告诉您,您可以获得所有详细信息……在未来的某个时间。 快来了

(This was published in 2008. But I've got such low expectations from MS doc, nothing surprises me) (这是 2008 年发布的。但我对 MS doc 的期望如此之低,没有什么让我感到惊讶)

I did manage to find a few other resources on the web.config.我确实设法在 web.config 上找到了一些其他资源。 So while attempting to get a masters level degree in IIS XML Config files, I have zeroed in on the following file contents:因此,在尝试在 IIS XML 配置文件中获得硕士学位时,我已经关注以下文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
           <add name="MyTest" path="example.time" verb="*" resourceType="Unspecified"  
             modules="IISHandler.MyHandler" preCondition="integratedMode"  />
       </handlers>
     </system.webServer>
</configuration>

All this should do is intercept a page request "example.time", and return the current time according to the original C# code in the tutorial.这要做的就是拦截一个页面请求“example.time”,并根据教程中的原始C#代码返回当前时间。

The response has been perpetually this:回应一直是这样的:

500错误

It's not telling me it can't FIND the module, only that it's bad.它并没有告诉我它找不到模块,只是说它很糟糕。 But with Microsoft, there's no telling what the real problem is.但是对于微软来说,真正的问题是什么并不清楚。

I tried (unsuccessfully) to just set module="IISHandler" even though that wouldn't make sense, as something still needs to know the class to invoke.我尝试(未成功)设置 module="IISHandler" 即使这没有意义,因为仍然需要知道 class 才能调用。 I was right, it still didn't work.我是对的,它仍然没有工作。

And continuing to search, all over the web there were suggestions to execute this command (which didn't make sense as the "features" were already added through the control panel):继续搜索,整个 web 都有执行此命令的建议(这没有意义,因为“功能”已通过控制面板添加):

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

That gave me an error:这给了我一个错误: cmd失败

(Telling me to install .NET 4.5 on my IIS 8 is just another MS deficiency) (告诉我在我的 IIS 8 上安装 .NET 4.5 只是 MS 的另一个缺陷)

My Add/Remove features for IIS 10 doesn't show 4.5 But it does show 4.8我的 IIS 10 的添加/删除功能未显示 4.5 但确实显示 4.8 添加删除

Is that significant?这很重要吗? I have no idea, and can't find any documentation.我不知道,也找不到任何文档。

I have also insured that the AppPool is set to "Integrated", and this Web app is in that pool我还确保 AppPool 设置为“Integrated”,并且此 Web 应用程序位于该池中应用程序池

But my choice is only .NET 2.0 or .NET 4.0... And yet the Add/Remove offers me 3.5, and NOT 2.0?但我的选择只有 .NET 2.0 或 .NET 4.0 ......但添加/删除为我提供了 3.5,而不是 2.0? My assembly is build in .NET 4.8 (I retried in 4 as well... no luck).我的程序集是在 .NET 4.8 中构建的(我也在 4 中重试......没有运气)。 And there is no 4.0 as an option in the Add/Remove under IIS 10.并且在 IIS 10 下的添加/删除中没有 4.0 作为选项。

What is the kludge of 2.0, 3.5, 4.0, 4.5, 4.8?? 2.0, 3.5, 4.0, 4.5, 4.8 的拼凑是什么??

But the real core on my question is: What is the process to get IIS to recognize my C# assembly and simply process a simple custom handler?但我的问题的真正核心是:让 IIS 识别我的 C# 程序集并简单地处理一个简单的自定义处理程序的过程是什么?

I hope this is enough information that someone can offer some assistance.我希望这是足够的信息,有人可以提供一些帮助。

TIA TIA

-SpacemanScott -太空人斯科特

Ironically enough, a fellow (remote) worker was trying to solve this same issue.具有讽刺意味的是,一位同事(远程)工作人员正试图解决同样的问题。 He informed me he got it working a few hours after I posted this.他告诉我,在我发布此消息几个小时后,他就开始工作了。

Here is the web.config:这是 web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <modules>
          <add name="MyModule" type="IISHandler.MyModule" />
        </modules>  
        <handlers>
            <add name="MyHandler" path="example.time" verb="*" resourceType="Unspecified" type="IISHandler.MyHandler" />
        </handlers>
    </system.webServer>
</configuration>

Although I still do not have the masters or PhD degree in IIS XML config files, the specific difference is that the <module> was added, and the "type" attribute was added to the <handler> to indicate the specific handler function.虽然我在IIS XML config文件中仍然没有硕士或博士学位,但具体的区别是添加了<module>,并且在<handler>中添加了“type”属性以指示具体的处理程序ZC1C4245268E687384F1C1C

Also the "module" attribute was removed from the <handler>, although this page seemed to indicate that was how the server knew where to find the module that provides the handler.此外,“模块”属性已从 <handler> 中删除,尽管此页面似乎表明服务器知道在哪里可以找到提供处理程序的模块。 Apparently not.显然不是。

The <module> is used to handle all requests during the processing sequence, and since that ability was not desired, it was not hand entered. <module> 用于在处理序列期间处理所有请求,并且由于不需要该功能,因此没有手动输入。 But apparently it is still necessary to tell the configuration that you will be using that assembly module.但显然仍然有必要告诉配置您将使用该组装模块。

If anyone runs into a similar problem, perhaps this will help.如果有人遇到类似的问题,也许这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何找出 iis7 的 404 错误处理程序中缺少哪个请求路径? - How do I find out which request path is missing in a 404 error handler in iis7? 添加自定义 IIS 处理程序 - Add custom IIS handler 在Windows 10的IIS 8.5中部署的WCF服务应用程序可永久加载而不会出现错误代码 - WCF Service Application deploy in IIS 8.5 on Windows 10 keep loading forever without error code 如何在IIS服务器上运行简单的服务器进程 - How do I run a simple server process on an IIS server 如何在 IIS 托管的网站中接收自定义 webhook? - How do I receive a custom webhook in an IIS hosted website? 如何在IIS 10上使用C#Razor获取Windows用户域/用户名? - How do you get Windows user domain/username with C# Razor on IIS 10? 在Visual Studio 2010和Windows 10中创建虚拟目录,IIS时出错 - Error creating virtual directory, IIS in visual studio 2010 and in windows 10 如何通过Wix或自定义操作修改IIS处理程序映射权限 - How to modify IIS handler mapping permissions via Wix or a Custom Action 如何使用Microsoft.Web.Administration命名空间在IIS7中干净地操作Handler Mappings? - How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace? 为什么将 blazor 部署到 IIS 时出现错误 - Why i have an error when deploy blazor to IIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM