.Net Core WebApi (b) deployed on Windows servers

  Previous learned how simple to create .Net Core Api and Swagger use , since write interface, you need to deploy to the server to be able to officially use. Server main use of the two systems, Windows and Linux, .Net and Microsoft Windows are belong to the father, then this one will start to deploy Windows Server System started.

First, prepare the server

  First, we need a cloud server installed Windows Server, but I did not. So, to end here. (╮ (¯ ▽ ¯) ╭ joke)

  Closer to home, we do not have a cloud server how to do, of course, it is to buy a. Some would say a little expensive, indeed, a month dozens of cheap, but it was in the case of uninterrupted use, since we do not need to learn it has been using, so we only need to buy [by meter fee] on the line.

  Ali goes to buy servers but found that:

  Ah, to 100 yuan to buy, decisively moved to other platforms.

  And then found Tencent cloud does not have this restriction, Tencent really close to the people ah. (Crazy hint)

 

  After my series of operations, found that the most expensive in Chengdu, one hour only 2 cents, much cheaper than going to the internet cafe. (Do not tell me you can not afford, grab a red envelope QQ can grab enough, not to mention the money spent on learning, and what investment (~ ¯ ▽ ¯) ~)

  According to the figure below, select [press] billing amount, selected area (I use the cheapest Chengdu), selected models (the cheapest, enough).

  Select public image, [Windows Server 2012 R2 Datacenter Edition 64 Chinese version], of course, if your English is good, you can choose the English version.

  Minimum system disk 50GB, not changed.

  Free distribution independent public network IP (important and must √ on, otherwise we lose the primary meaning)

  Select [Billing] Bandwidth (how much traffic because you are not allowed to use Paul)

  Next set the host, select [New] security group, and then drop down box [put] through all ports (because we are learning for temporary use, what security issues do not care about)

  Then [password], this I do not say it.

  [Destroy] the timing of this depends on what you do not use, you can also choose to manually run after the destruction, but if you forget, it will be time to continue deducting money. (Be sure to set the timing of the destruction of a good time, or else you will find that with the use of a sudden gone)

  Confirmation, nothing to say, opened.

  Two cents an hour just toss you, is not very cost-effective.

  Examples of the console automatically jump to the page after the opening, we can see the public IP network.

  Then we Remote Desktop Connection.

  If you can not connect error occurred.

  Returning to our console, click in the Action column [Login]. 

  Scan code prompted micro-channel operation, open micro-channel scan code, determined.

  After determining the pop-up login window Windows instances, click in other ways (VNC) [Sign in now].

  The new pop-up page, login prompt press Ctrl + Alt + Delete. Then you directly on the keyboard, press Ctrl + Alt + Delete, but found open your own computer security window ╮ (¯ ▽ ¯) ╭, in fact, points to send remote commands to operate.

  Open the top right corner [send remote commands], click [Ctrl-Alt-Delete] login.

  Enter the account password After logging in, open the System Properties, the [only allowed to use the network to run a network-level authentication of the remote desktop computer connection] to remove the hook.

  After exit pages, re-Remote Desktop Connection, on it.

  Enter the user name and password to log in, get.

  Well, cloud services bought, then the access to our to business.

Second, the environment to build and publish

  First, we need to download the .NET Core Runtime on the server, attach the link below.

  https://dotnet.microsoft.com/download/dotnet-core

  Choose our .NET Core version, I was 2.2.

  As shown, download the latest.

  After the download is complete, run the exe file, check agree to install, and then wait for the installation to complete on the line.

  Then back to our previous project, right item, choose publish.

  Select target release, select the folder, select the path (I use the default path) and click Post.

  Then find your published folder, copy the folder to the server.

  To the server copy, rename the name of the project, easy to distinguish.

  As follows.

Third, the deployment

  I There are two deployment methods, the first is to perform command-line operation, the second is through the deployment of IIS. A second common recommended deployment of IIS, first as understand the use, of course, you want to use is also possible.

The first way to execute the command line:

  Hold down the Shift key and do not, right-blank, pop-up menu there are [here] to open a command window, click on it to open a named window.

  We will find a path directly cmd folder in the file, and then execute the following command (FirstApi your project name, which is the figure above FirstApi.dll file).

  dotnet FirstApi.dll

  You will find an address, monitor local port 5000.

  Then enter the address will be able to visit. Oh, how the internal error o (゚ Д ゚) っ!

  Look at our command window, the original file is missing. This file is generated Swagger xml annotation files, vs released when not included in it, so we have to manually copy the file over.

  Find the xml file copied to the server folder.

  Re-run, you can see the access address. But this is localhost local, we want to access outside the network you need to change the code (of course, you can also use a reverse proxy).

 

  Open our project, click on Program Files.

  FIG tagging in the position indicated by the arrow 5555 is your specified port.

  After addition of the Program class file code shown below.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace FirstApi
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args).UseUrls("http://*:5555")
                .UseStartup<Startup>();
    }
}

  And regenerate copy the dll cover to the server, run in the previous embodiment.

  Public network ip plus input port, will be able to successfully interviewed on their computers.

  We can test. Try implementation of a successful return results.

  Then enter our second approach.

The second way through IIS Deployment:

  First, open Server Manager. (Note: Because I was followed by a first mode of operation, please ensure that have xml file copying server folder, or completed the deployment will be wrong)

  In Management in [click Add Roles and Features]

  To select server roles, check the [Web Server (IIS)].

  And then select the server role, on demand check. (I are on the hook, in order to avoid problems, anyway, do not have to add not much harm (~ ¯ ▽ ¯) ~).

  After the installation is complete, open our IIS Manager.

  Right website, select Add Site. Enter the site name, select a file path, the input port.

  Then click [Application Pool], opening the editor we just created.

  The .NET CLR version of the drop-down box to select the managed code is [no], OK.

  Then open the site, but also being given (ŎдŎ;), I checked the [lack of] AspNetCoreModule managed module.

  Select the server root, open the [module] this one.

  Called the discovery did not find [the] AspNetCoreModule managed module, emmmmm seems to be missing.

  We re-open the downloaded installer, click [Repair] reinstalled.

  Wait for the re-installation is complete, restart the IIS Manager, open again [module], has been found.

  Then we visit the site, success appears Swagger document pages, you're done.

  OK, .Net Core WebApi deployed on Windows servers here came to an end, I believe you will be right, I feel good little friends can recommend it to the right → point (〃 ^ ω ^), insufficient places please raised, a lot of attention. Next is deployed on Linux servers, and is in fact a way similar to the above, but in order to distinguish, separate write (in fact, to water a) how to build a record, you want to understand the small partners can focus I yo / (// • /ω/ • //) /.

Guess you like

Origin www.cnblogs.com/LYF1997/p/11507747.html