将 HttpModule .Net 类库移植到 .Net Core Web API [英] Porting HttpModule .Net Class Library to .Net Core Web API

查看:21
本文介绍了将 HttpModule .Net 类库移植到 .Net Core Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个项目从 .net Web 应用程序迁移到 .Net 核心 Web API.

I am migrating a project from .net Web Application to .Net core Web API.

我在 IIS 集成模式下使用 HTTP 模块,它是 .net 框架类库.

I am using HTTP Module which is .net framework class library, in IIS Integrated mode.

所以,考虑按原样移植到我的新核心应用程序中.

So, thought to port as it is, to my new core app.

我将 web.config 粘贴到我的新核心应用中,并添加了对该 Http 模块的项目引用,然后它就开始工作了.

I pasted web.config to my new core app and added a project reference to that Http Module and it started working.

我的 BeginRequest 方法中有一些 Context.Response.Write,每当我调用 Web api 时,我都能看到这些行.

I am having some Context.Response.Write in my BeginRequest method, and I can see those lines whenever I am making a call to my web api.

但是,我在这里有一些问题.

But, I am having some questions here.

  1. 模块中没有出现断点.
  2. 我认为没有加载任何符号,所以我查看了 VS 中的模块窗口,但没有加载此类模块.
  3. 当非核心项目加载到核心项目时加载符号的任何方式.
  4. 想知道如何在不加载引用的情况下调用模块.

有人可以分享关于以上几点的一些意见.

Could some one share some inputs on above points.

谢谢.

推荐答案

HTTP 模块是经典 ASP.NET/IIS 应用程序模型的一个概念.

HTTP Modules are a concept of the classic ASP.NET / IIS application model.

ASP.NET Core 不使用 IIS 的事件系统,IIS 收到的请求被转发到 ASP.NET Core 应用程序,由该应用程序处理并返回.

ASP.NET Core does not use IIS' event system, the requests that IIS received are forwarded to the ASP.NET Core app, processed by this application and returned.

如果您在 web.config 中使用 http 模块,则不能很好地保证它有机会在正确的时间处理部分请求/响应.此外,如果模块排序正常工作,您将无法在 IIS 之外托管应用程序 - 您将有效地并行运行 ASP.NET Core 和 ASP.NET.

If you are using an http module inside a web.config, there isn't a good guarantee that it will have a chance to process parts of the request/response at the right times. Also, you will not be able to host the app outside of IIS if you ever get the module ordering working correctly - you would effectively be running ASP.NET Core and ASP.NET side-by-side.

如果您想将类似模块的功能移植到 ASP.NET Core 应用程序,最好的起点是中间件.ASP 中的 中间件.NET Core 是处理管道的一部分,可以在应用程序定义的管道中的某个点处理传入请求和传出响应.

If you want to port module-like functionality to an ASP.NET Core app, the best place to start is a Middleware. A middleware in ASP.NET Core is part of the processing pipeline and gets to process incoming requests and outgoing response at a point in the pipeline defined by the application.

这篇关于将 HttpModule .Net 类库移植到 .Net Core Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆