posinformatique.aspnetcore.server.aspnet是一個基於.NET框架的ASP .NET非核心(WebForms和MVC)基礎架構的ASP .NET Core Web API的庫。


posinformatique.aspnetcore.server.aspnet是ASP .NET非核心IHttpHandler ,根據ASP .NET非核心基礎架構中配置的路由執行。當posinformatique.aspnetcore.server.aspnet IHttpHandler內部實現被調用時,HTTP查詢將發送到ASP .NET核心基礎架構,如果在專用的IIS,Console或Kestrel主機中託管,則以相同的行為執行該查詢。
posinformatique.aspnetcore.server.aspnet可直接在Nuget官方網站上獲得。使用以下Nuget命令行下載並安裝庫到您的Visual Studio項目
Install-Package PosInformatique.AspNetCore.Server.AspNet
在新的ASP .NET Web Forms/MVC非核心項目中,使用以下Nuget命令安裝ASP .NET Core 2.x基礎架構:
Install-Package Microsoft.AspNetCore
Install-Package Microsoft.AspNetCore.Mvc
在您的ASP .NET WebForms或MVC非核心項目中添加posinformatique.aspnetcore.server.aspnet包裝套件之後,在您的HttpApplication類的Application_Start中構建並啟動ASP .NET核心核心IWebHost實例,使用Classic web host.creathost.createatefefefefefefefeffbuilder( Startup API WebHost.CreateDefaultBuilder() (啟動API)(啟動)。相反,要選擇kestrel或iis託管您的ASP .NET Core應用程序,請調用UseAspNet()方法,以在ASP .NET非核心基礎結構上託管您的ASP .NET Core應用程序。
UseAspNet()需要定義將通過ASP .NET核心基礎架構而不是ASP .NET非核心進行截獲並處理的基本路線。
這是構建構建,啟動ASP .NET Core應用程序的Global.asax.cs代碼的一個示例,並將所有請求重定向/api和/swagger URL啟動到ASP .NET CORE應用程序:
public class Global : System . Web . HttpApplication
{
protected void Application_Start ( object sender , EventArgs e )
{
WebHost . CreateDefaultBuilder ( )
. UseAspNet ( options =>
{
options . Routes . Add ( "api" ) ;
options . Routes . Add ( "swagger" ) ;
} )
. UseStartup < Startup > ( )
. Start ( ) ;
}
}您可以通過註冊其他服務來與Startup類配置ASP .NET Core應用程序。這是一個Startup類的示例,該類別註冊ASP .NET Core MVC基礎架構和SwashBuckle.aspNetcore擴展程序,以使用Swagger UI添加文檔。
public class Startup
{
public Startup ( IConfiguration configuration )
{
Configuration = configuration ;
}
public IConfiguration Configuration { get ; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices ( IServiceCollection services )
{
services . AddMvc ( ) ;
services . AddSwaggerGen ( c =>
{
c . SwaggerDoc ( "v1" , new Info { Title = "My API" , Version = "v1" } ) ;
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $ " { Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name } .xml" ;
var xmlPath = Path . Combine ( AppContext . BaseDirectory , "bin" , xmlFile ) ;
c . IncludeXmlComments ( xmlPath ) ;
} ) ;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
{
if ( env . IsDevelopment ( ) )
{
app . UseDeveloperExceptionPage ( ) ;
}
app . UseMvc ( routes =>
{
routes . MapRoute (
name : "default" ,
template : "{controller=Home}/{action=Index}/{id?}" ) ;
} ) ;
// Enable middleware to serve generated Swagger as a JSON endpoint.
app . UseSwagger ( ) ;
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app . UseSwaggerUI ( c =>
{
c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "My API V1" ) ;
} ) ;
}
} 您必須確定僅在控制器實現內使用ASP .NET核心的組件和服務。避免從控制器實現中訪問ASP .NET非核心的組件或服務。例如,請確保訪問控制器代碼內部的ASP .NET Core HttpContext ,並且不使用ASP .NET非核心HttpContext 。

如先前的體系結構圖中所示,在您的控制器代碼中,您只能用於ASP .NET Core API,即使您可以訪問ASP .NET非核心基礎架構API。
因為ASP .NET Core 3.X僅基於.NET Core 3.0運行時(而不是像以前一樣,在.NET標準2.0上,例如ASP .NET Core 2.x),因此該庫不能用於託管ASP .NET Core 3.X Web API,ar asp .NET .NET非核心基礎架構。
當前, posinformatique.aspnetcore.server.aspnet只能與RAW ASP .NET核心基礎結構和Web API控制器實現一起使用。由於Visual Studio Project使用ASP .NET非核心Web編譯器,因此無法將此庫與MVC Razor視圖一起使用。
請不要猶豫,克隆我的代碼並提交一些更改...這是一個開源項目,因此歡迎每個人都可以改進這個庫...順便說一句,我是法國人...所以也許您會說我的英語並不是真正流利的...所以請不要猶豫,請不要修復我的資源字符串或文檔... Merci ... Merci!
我要感謝Dilitrust Company測試,並向我提供了此庫的反饋,以提供嵌入在ASP .NET Core Web上開發的ASP .NET WebForms應用程序。