简体   繁体   English

将 ASP.Net 添加到现有项目

[英]Add ASP.Net to existing project

I'm new to ASP.Net and I have the following scenario: I have a.Net Framework project folder with several projects.我是 ASP.Net 的新手,我有以下场景:我有一个包含多个项目的 .Net Framework 项目文件夹。 All of them are configured.Net Framework 4.7.2 and I have a dependency I can not change at the moment.所有这些都配置了.Net Framework 4.7.2,我有一个目前无法更改的依赖项。 So migrating to.Net Core is not an option at the moment.所以迁移到 .Net Core 目前不是一个选择。

My question is the following: What is the correct approach to add the functionality of a RESTful server with ASP.Net?我的问题如下:使用 ASP.Net 添加 RESTful 服务器功能的正确方法是什么?

I don't want to implement a frontend.我不想实现前端。 I just want to add a server to my projects.我只想在我的项目中添加一个服务器。

In https://docs.microsoft.com/en-us/dotnet/standard/choosing-core-framework-server it says, "In most cases, you don't need to migrate your existing applications to .NET 5. Instead, a recommended approach is to use .NET 5 as you extend an existing application, such as writing a new web service in ASP.NET Core."https://docs.microsoft.com/en-us/dotnet/standard/choosing-core-framework-server它说,“在大多数情况下,您不需要将现有应用程序迁移到 .NET 5。相反,推荐的方法是在扩展现有应用程序时使用 .NET 5,例如在 ASP.NET 内核中编写新的 web 服务。”

How should I do that?我该怎么做?

I'm really confused.我真的很困惑。 Please help me.请帮我。 Maybe some hints or links to other pages are enough to lead me into the right direction:)也许一些提示或指向其他页面的链接足以引导我走向正确的方向:)

Kind regards Chris亲切的问候克里斯

It basically depends on your future preference and time, If the organisation is pretty much aligned with .netcore what you can do is you can easily migrate .net framework project to.Net standard and create a new.Net core project with API endpoints defined and you can easily refer the.Net standard libraries directly to it.这基本上取决于您未来的偏好和时间,如果组织与 .netcore 非常一致,您可以做的是您可以轻松地将 .net 框架项目迁移到 .Net 标准并创建一个新的 .Net 核心项目,其中定义了 API 端点并且您可以很容易地将.Net标准库直接引用到它。 https://docs.microsoft.com/en-us/dotnet/core/porting/ https://docs.microsoft.com/en-us/dotnet/core/porting/

But if you want to stick to.Net framework libraries, you can create basic Asp.Net core web API with DotNetframework, It is not a legacy framework, it has the latest release within 3 months and it is also battle-tested, But you can only host in windows machines unlike.Net core which you can host in windows/linux但是如果你想坚持.Net框架库,你可以创建基本的Asp.Net core web API with DotNetframework,它不是遗留框架,它有3个月内的最新版本,也是经过实战考验的,但是你只能托管在 windows 机器上,这与可以托管在 windows/linux 中的.Net 核心不同

https://developer.okta.com/blog/2018/07/27/build-crud-app-in-aspnet-framework-webapi-and-angular https://developer.okta.com/blog/2018/07/27/build-crud-app-in-aspnet-framework-webapi-and-angular

any .net project that running on a web server supports REST calls.在 web 服务器上运行的任何 .net 项目都支持 REST 调用。 In fact if you make a webmethod?事实上,如果你制作一个网络方法?

Say this code:说这段代码:

<WebMethod()>
Public Function HelloWorld() As String

    If keyid <> 123 Then Exit Function

    Return "Hello World from server"
End Function

Then right out of the box with ONLY the above code?然后只用上面的代码开箱即用? The above supports SOAP 1.1, 1.2, and post (REST) calls.以上支持 SOAP 1.1、1.2 和 post (REST) 调用。

So there is no "concept" in asp.net that you "adopt" SOME kind of RESTful server - the server you use in this case is IIS, and it supports REST calls out of the box, and always did from day one to my knowledge.因此,asp.net 中没有“采用”某种 RESTful 服务器的“概念”——在这种情况下,您使用的服务器是 IIS,它支持 Z50780F47F6839D47D60BC455ZEE00。 You MOST certainly have to run a web server, but making REST calls does not require a "special" RESTful server, but just in fact that you running a web server - in this case IIS or so called internet services. You MOST certainly have to run a web server, but making REST calls does not require a "special" RESTful server, but just in fact that you running a web server - in this case IIS or so called internet services.

If you already have a project that supports and API just add an additional controller, assuming the functionality is not closely related to existing functionality.如果您已经有一个支持 API 的项目,只需添加一个额外的 controller,假设该功能与现有功能没有密切相关。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM