{"id":1160,"date":"2025-05-27T14:48:15","date_gmt":"2025-05-27T06:48:15","guid":{"rendered":"https:\/\/www.hyy.net\/?p=1160"},"modified":"2025-05-27T14:48:15","modified_gmt":"2025-05-27T06:48:15","slug":"ultimate-asp-net-core-web-api-31-deployment-to-iis","status":"publish","type":"post","link":"https:\/\/diji.net\/?p=1160","title":{"rendered":"Ultimate ASP.NET Core Web API 31 DEPLOYMENT TO IIS"},"content":{"rendered":"<p>31 DEPLOYMENT TO IIS<br \/>\n30 \u90e8\u7f72\u5230 IIS<\/p>\n<p>Before we start the deployment process, we would like to point out one important thing. We should always try to deploy an application on at least a local machine to somehow simulate the production environment as soon as we start with development. That way, we can observe how the application behaves in a production environment from the beginning of the development process.\u200c<br \/>\n\u5728\u5f00\u59cb\u90e8\u7f72\u8fc7\u7a0b\u4e4b\u524d\uff0c\u6211\u4eec\u60f3\u6307\u51fa\u4e00\u4ef6\u91cd\u8981\u7684\u4e8b\u60c5\u3002\u4e00\u65e6\u5f00\u59cb\u5f00\u53d1\uff0c\u6211\u4eec\u5e94\u8be5\u59cb\u7ec8\u5c1d\u8bd5\u81f3\u5c11\u5728\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\uff0c\u4ee5\u67d0\u79cd\u65b9\u5f0f\u6a21\u62df\u751f\u4ea7\u73af\u5883\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u5f00\u53d1\u8fc7\u7a0b\u7684\u4e00\u5f00\u59cb\u5c31\u89c2\u5bdf\u5e94\u7528\u7a0b\u5e8f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u884c\u4e3a\u3002<\/p>\n<p>That leads us to the conclusion that the deployment process should not be the last step of the application\u2019s lifecycle. We should deploy our application to the staging environment as soon as we start building it.<br \/>\n\u8fd9\u4f7f\u6211\u4eec\u5f97\u51fa\u7ed3\u8bba\uff0c\u90e8\u7f72\u8fc7\u7a0b\u4e0d\u5e94\u8be5\u662f\u5e94\u7528\u7a0b\u5e8f\u751f\u547d\u5468\u671f\u7684\u6700\u540e\u4e00\u6b65\u3002\u6211\u4eec\u5e94\u8be5\u5728\u5f00\u59cb\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u540e\u7acb\u5373\u5c06\u5176\u90e8\u7f72\u5230\u6682\u5b58\u73af\u5883\u3002<\/p>\n<p>That said, let\u2019s start with the deployment process.<br \/>\n\u4e5f\u5c31\u662f\u8bf4\uff0c\u8ba9\u6211\u4eec\u4ece\u90e8\u7f72\u8fc7\u7a0b\u5f00\u59cb\u3002<\/p>\n<h2>31.1 Creating Publish Files<\/h2>\n<p>31.1 \u521b\u5efa Publish \u6587\u4ef6<\/p>\n<p>Let\u2019s create a folder on the local machine with the name Publish. Inside that folder, we want to place all of our files for deployment. After the folder creation, let\u2019s right-click on the main project in the Solution Explorer window and click publish option:\u200c<br \/>\n\u8ba9\u6211\u4eec\u5728\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a Publish \u7684\u6587\u4ef6\u5939\u3002\u5728\u8be5\u6587\u4ef6\u5939\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u653e\u7f6e\u6240\u6709\u7528\u4e8e\u90e8\u7f72\u7684\u6587\u4ef6\u3002\u521b\u5efa\u6587\u4ef6\u5939\u540e\uff0c\u8ba9\u6211\u4eec\u53f3\u952e\u5355\u51fb Solution Explorer \u7a97\u53e3\u4e2d\u7684\u4e3b\u9879\u76ee\uff0c\u7136\u540e\u5355\u51fb publish \u9009\u9879\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3101.jpg\" alt=\"alt text\" \/><\/p>\n<p>In the \u201cPick a publish target\u201d window, we are going to choose the Folder option and click Next:<br \/>\n\u5728\u201cPick a publish target\u201d\u7a97\u53e3\u4e2d\uff0c\u6211\u4eec\u5c06\u9009\u62e9 Folder \u9009\u9879\uff0c\u7136\u540e\u5355\u51fb Next\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3102.jpg\" alt=\"alt text\" \/><\/p>\n<p>And point to the location of the Publish folder we just created and click Finish:<br \/>\n\u5e76\u6307\u5411\u6211\u4eec\u521a\u521a\u521b\u5efa\u7684 Publish \u6587\u4ef6\u5939\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u5355\u51fb Finish\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3103.jpg\" alt=\"alt text\" \/><br \/>\nPublish windows can be different depending on the Visual Studio version.<br \/>\n\u53d1\u5e03\u7a97\u53e3\u53ef\u80fd\u56e0 Visual Studio \u7248\u672c\u800c\u5f02\u3002<\/p>\n<p>After that, we have to click the Publish button:<br \/>\n\u4e4b\u540e\uff0c\u6211\u4eec\u5fc5\u987b\u5355\u51fb Publish \u6309\u94ae\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3104.jpg\" alt=\"alt text\" \/><\/p>\n<p>Visual Studio is going to do its job and publish the required files in the specified folder.<br \/>\nVisual Studio \u5c06\u6267\u884c\u5176\u5de5\u4f5c\u5e76\u5728\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\u53d1\u5e03\u6240\u9700\u7684\u6587\u4ef6\u3002<\/p>\n<h2>31.2 Windows Server Hosting Bundle<\/h2>\n<p>31.2 Windows Server \u6258\u7ba1\u6346\u7ed1\u5305<\/p>\n<p>Before any further action, let\u2019s install the .NET Core Windows Server Hosting bundle on our system to install .NET Core Runtime. Furthermore, with this bundle, we are installing the .NET Core Library and the ASP.NET Core Module. This installation will create a reverse proxy between IIS and the Kestrel server, which is crucial for the deployment process.\u200c<br \/>\n\u5728\u6267\u884c\u4efb\u4f55\u8fdb\u4e00\u6b65\u4f5c\u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5 .NET Core Windows Server \u6258\u7ba1\u6346\u7ed1\u5305\u4ee5\u5b89\u88c5 .NET Core \u8fd0\u884c\u65f6\u3002\u6b64\u5916\uff0c\u901a\u8fc7\u6b64\u6346\u7ed1\u5305\uff0c\u6211\u4eec\u5c06\u5b89\u88c5 .NET Core \u5e93\u548c ASP.NET Core Module\u3002\u6b64\u5b89\u88c5\u5c06\u5728 IIS \u548c Kestrel \u670d\u52a1\u5668\u4e4b\u95f4\u521b\u5efa\u53cd\u5411\u4ee3\u7406\uff0c\u8fd9\u5bf9\u4e8e\u90e8\u7f72\u8fc7\u7a0b\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>If you have a problem with missing SDK after installing the Hosting Bundle, follow this solution suggested by Microsoft:<br \/>\n\u5982\u679c\u60a8\u5728\u5b89\u88c5 Hosting Bundle \u540e\u9047\u5230\u7f3a\u5c11 SDK \u7684\u95ee\u9898\uff0c\u8bf7\u9075\u5faa Microsoft \u5efa\u8bae\u7684\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>Installing the .NET Core Hosting Bundle modifies the PATH when it installs the .NET Core runtime to point to the 32-bit (x86) version of .NET Core (C:\\Program Files (x86)\\dotnet). This can result in missing SDKs when the 32-bit (x86) .NET Core dotnet command is used (No .NET Core SDKs were detected). To resolve this problem, move C:\\Program Files\\dotnet\\to a position before C:\\Program Files (x86)\\dotnet\\ on the PATH environment variable.<br \/>\n\u5b89\u88c5 .NET Core \u6258\u7ba1\u6346\u7ed1\u5305\u4f1a\u5728\u5b89\u88c5 .NET Core \u8fd0\u884c\u65f6\u65f6\u4fee\u6539 PATH\uff0c\u4f7f\u5176\u6307\u5411 .NET Core \u7684 32 \u4f4d \uff08x86\uff09 \u7248\u672c \uff08C\uff1a\\Program Files \uff08x86\uff09\\dotnet\uff09\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5728\u4f7f\u7528 32 \u4f4d \uff08x86\uff09 .NET Core dotnet \u547d\u4ee4\u65f6\u7f3a\u5c11 SDK\uff08\u672a\u68c0\u6d4b\u5230 .NET Core SDK\uff09\u3002\u82e5\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u5c06 C\uff1a\\Program Files\\dotnet\\ \u79fb\u52a8\u5230 PATH \u73af\u5883\u53d8\u91cf\u4e0a C\uff1a\\Program Files \uff08x86\uff09\\dotnet\\ \u4e4b\u524d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>After the installation, we are going to locate the Windows hosts file on C:\\Windows\\System32\\drivers\\etc and add the following record at the end of the file:<br \/>\n\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c06\u5728 C\uff1a\\Windows\\System32\\drivers\\etc \u4e0a\u627e\u5230 Windows \u4e3b\u673a\u6587\u4ef6\uff0c\u5e76\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u8bb0\u5f55\uff1a<\/p>\n<pre><code>127.0.0.1 www.companyemployees.codemaze<\/code><\/pre>\n<p>After that, we are going to save the file.<br \/>\n\u4e4b\u540e\uff0c\u6211\u4eec\u5c06\u4fdd\u5b58\u6587\u4ef6\u3002<\/p>\n<p>31.3 Installing IIS<br \/>\n31.3 \u5b89\u88c5 IIS<\/p>\n<p>If you don\u2019t have IIS installed on your machine, you need to install it by opening ControlPanel and then Programs and Features:\u200c<br \/>\n\u5982\u679c\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u6ca1\u6709\u5b89\u88c5 IIS\uff0c\u5219\u9700\u8981\u901a\u8fc7\u6253\u5f00 ControlPanel\uff0c\u7136\u540e\u6253\u5f00\u201c\u7a0b\u5e8f\u548c\u529f\u80fd\u201d\u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3105.jpg\" alt=\"alt text\" \/><\/p>\n<p>After the IIS installation finishes, let\u2019s open the Run window (windows key + R) and type: inetmgr to open the IIS manager:<br \/>\nIIS \u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8ba9\u6211\u4eec\u6253\u5f00 Run \u7a97\u53e3\uff08Windows \u952e + R\uff09\u5e76\u952e\u5165\uff1ainetmgr \u4ee5\u6253\u5f00 IIS \u7ba1\u7406\u5668\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3106.jpg\" alt=\"alt text\" \/><\/p>\n<p>Now, we can create a new website:<br \/>\n\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7f51\u7ad9\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3107.jpg\" alt=\"alt text\" \/><\/p>\n<p>In the next window, we need to add a name to our site and a path to the published files:<br \/>\n\u5728\u4e0b\u4e00\u4e2a\u7a97\u53e3\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u6211\u4eec\u7684\u7f51\u7ad9\u6dfb\u52a0\u4e00\u4e2a\u540d\u79f0\u548c\u4e00\u4e2a\u5df2\u53d1\u5e03\u6587\u4ef6\u7684\u8def\u5f84\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3108.jpg\" alt=\"alt text\" \/><\/p>\n<p>And click the OK button.<br \/>\n\u7136\u540e\u70b9\u51fb OK \u6309\u94ae\u3002<\/p>\n<p>After this step, we are going to have our site inside the \u201csites\u201d folder in the IIS Manager. Additionally, we need to set up some basic settings for our application pool:<br \/>\n\u5b8c\u6210\u6b64\u6b65\u9aa4\u540e\uff0c\u6211\u4eec\u5c06\u7ad9\u70b9\u7f6e\u4e8e IIS Manager \u7684 \u201csites\u201d \u6587\u4ef6\u5939\u4e2d\u3002\u6b64\u5916\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u5e94\u7528\u7a0b\u5e8f\u6c60\u8bbe\u7f6e\u4e00\u4e9b\u57fa\u672c\u8bbe\u7f6e\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3109.jpg\" alt=\"alt text\" \/><\/p>\n<p>After we click on the Basic Settings link, let\u2019s configure our application pool:<br \/>\n\u5355\u51fb Basic Settings \u94fe\u63a5\u540e\uff0c\u8ba9\u6211\u4eec\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u6c60\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3110.jpg\" alt=\"alt text\" \/><\/p>\n<p>ASP.NET Core runs in a separate process and manages the runtime. It doesn't rely on loading the desktop CLR (.NET CLR). The Core Common Language Runtime for .NET Core is booted to host the app in the worker process. Setting the .NET CLR version to No Managed Code is optional but recommended.<br \/>\nASP.NET Core \u5728\u5355\u72ec\u7684\u8fdb\u7a0b\u4e2d\u8fd0\u884c\u5e76\u7ba1\u7406\u8fd0\u884c\u65f6\u3002\u5b83\u4e0d\u4f9d\u8d56\u4e8e\u52a0\u8f7d\u684c\u9762 CLR \uff08.NET CLR\uff09\u3002.NET Core \u7684\u6838\u5fc3\u516c\u5171\u8bed\u8a00\u8fd0\u884c\u65f6\u542f\u52a8\uff0c\u4ee5\u5728\u5de5\u4f5c\u8fdb\u7a0b\u4e2d\u6258\u7ba1\u5e94\u7528\u3002\u5c06 .NET CLR \u7248\u672c\u8bbe\u7f6e\u4e3a\u201c\u65e0\u6258\u7ba1\u4ee3\u7801\u201d\u662f\u53ef\u9009\u7684\uff0c\u4f46\u5efa\u8bae\u4f7f\u7528\u3002<\/p>\n<p>Our website and the application pool should be started automatically.<br \/>\n\u6211\u4eec\u7684\u7f51\u7ad9\u548c\u5e94\u7528\u7a0b\u5e8f\u6c60\u5e94\u8be5\u4f1a\u81ea\u52a8\u542f\u52a8\u3002<\/p>\n<p>31.4 Configuring Environment File<br \/>\n31.4 \u914d\u7f6e\u73af\u5883\u6587\u4ef6<\/p>\n<p>In the section where we configured JWT, we had to use a secret key that we placed in the environment file. Now, we have to provide to IIS the name of that key and the value as well.\u200c<br \/>\n\u5728\u914d\u7f6e JWT \u7684\u90e8\u5206\u4e2d\uff0c\u6211\u4eec\u5fc5\u987b\u4f7f\u7528\u653e\u7f6e\u5728\u73af\u5883\u6587\u4ef6\u4e2d\u7684\u5bc6\u94a5\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5fc5\u987b\u5411 IIS \u63d0\u4f9b\u8be5\u952e\u7684\u540d\u79f0\u548c\u503c\u3002<\/p>\n<p>The first step is to click on our site in IIS and open Configuration Editor:<br \/>\n\u7b2c\u4e00\u6b65\u662f\u5728 IIS \u4e2d\u5355\u51fb\u6211\u4eec\u7684\u7ad9\u70b9\u5e76\u6253\u5f00\u914d\u7f6e\u7f16\u8f91\u5668\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3111.jpg\" alt=\"alt text\" \/><\/p>\n<p>Then, in the section box, we are going to choose system.webServer\/aspNetcore:<br \/>\n\u7136\u540e\uff0c\u5728\u90e8\u5206\u6846\u4e2d\uff0c\u6211\u4eec\u5c06\u9009\u62e9 system.webServer\/aspNetcore\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3112.jpg\" alt=\"alt text\" \/><\/p>\n<p>From the \u201cFrom\u201d combo box, we are going to choose ApplicationHost.config:<br \/>\n\u4ece \u201cFrom\u201d \u7ec4\u5408\u6846\u4e2d\uff0c\u6211\u4eec\u5c06\u9009\u62e9 ApplicationHost.config\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3113.jpg\" alt=\"alt text\" \/><\/p>\n<p>After that, we are going to select environment variables:<br \/>\n\u4e4b\u540e\uff0c\u6211\u4eec\u5c06\u9009\u62e9\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3114.jpg\" alt=\"alt text\" \/><\/p>\n<p>Click Add and type the name and the value of our variable:<br \/>\n\u5355\u51fb Add \u5e76\u952e\u5165\u53d8\u91cf\u7684\u540d\u79f0\u548c\u503c\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3115.jpg\" alt=\"alt text\" \/><\/p>\n<p>As soon as we click the close button, we should click apply in the next window, restart our application in IIS, and we are good to go.<br \/>\n\u5355\u51fb\u5173\u95ed\u6309\u94ae\u540e\uff0c\u6211\u4eec\u5e94\u8be5\u5728\u4e0b\u4e00\u4e2a\u7a97\u53e3\u4e2d\u5355\u51fb\u5e94\u7528\uff0c\u5728 IIS \u4e2d\u91cd\u65b0\u542f\u52a8\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5f00\u59cb\u4e86\u3002<\/p>\n<h2>31.5 Testing Deployed Application<\/h2>\n<p>31.5 \u6d4b\u8bd5\u5df2\u90e8\u7f72\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>Let\u2019s open Postman and send a request for the Root document:\u200c<br \/>\n\u8ba9\u6211\u4eec\u6253\u5f00 Postman \u5e76\u53d1\u9001\u6839\u6587\u6863\u7684\u8bf7\u6c42\uff1a<br \/>\n<a href=\"http:\/\/www.companyemployees.codemaze\/api\">http:\/\/www.companyemployees.codemaze\/api<\/a><\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3116.jpg\" alt=\"alt text\" \/><\/p>\n<p>We can see that our API is working as expected. If it\u2019s not, and you have a problem related to web.config in IIS, try reinstalling the Server Hosting Bundle package.<br \/>\n\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u7684 API \u6b63\u5728\u6309\u9884\u671f\u5de5\u4f5c\u3002\u5982\u679c\u4e0d\u662f\uff0c\u5e76\u4e14\u60a8\u5728 IIS \u4e2d\u5b58\u5728\u4e0e web.config \u76f8\u5173\u7684\u95ee\u9898\uff0c\u8bf7\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5 Server Hosting Bundle \u5305\u3002<\/p>\n<p>If you get an error message that the Presentation.xml file is missing, you can copy it from the project and paste it into the Publish folder. Also, in the Properties window for that file, you can set it to always copy during the publish.<br \/>\n\u5982\u679c\u6536\u5230\u4e00\u6761\u9519\u8bef\u6d88\u606f\uff0c\u6307\u51fa Presentation.xml \u6587\u4ef6\u7f3a\u5931\uff0c\u5219\u53ef\u4ee5\u4ece\u9879\u76ee\u4e2d\u590d\u5236\u8be5\u6587\u4ef6\u5e76\u5c06\u5176\u7c98\u8d34\u5230 Publish \u6587\u4ef6\u5939\u4e2d\u3002\u6b64\u5916\uff0c\u5728\u8be5\u6587\u4ef6\u7684 Properties \uff08\u5c5e\u6027\uff09 \u7a97\u53e3\u4e2d\uff0c\u60a8\u53ef\u4ee5\u5c06\u5176\u8bbe\u7f6e\u4e3a\u5728\u53d1\u5e03\u671f\u95f4\u59cb\u7ec8\u590d\u5236\u3002<\/p>\n<p>Now, let\u2019s continue.<br \/>\n\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u7ee7\u7eed\u3002<\/p>\n<p>We still have one more thing to do. We have to add a login to the SQL Server for IIS APPPOOL\\CodeMaze Web Api and grant permissions to the database. So, let\u2019s open the SQL Server Management Studio and add a new login:<br \/>\n\u6211\u4eec\u8fd8\u6709\u4e00\u4ef6\u4e8b\u8981\u505a\u3002\u6211\u4eec\u5fc5\u987b\u5411 SQL Server for IIS APPPOOL\\CodeMaze Web Api \u6dfb\u52a0\u767b\u5f55\u540d\uff0c\u5e76\u6388\u4e88\u5bf9\u6570\u636e\u5e93\u7684\u6743\u9650\u3002\u56e0\u6b64\uff0c\u8ba9\u6211\u4eec\u6253\u5f00 SQL Server Management Studio \u5e76\u6dfb\u52a0\u65b0\u7684\u767b\u5f55\u540d\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3117.jpg\" alt=\"alt text\" \/><\/p>\n<p>In the next window, we are going to add our user:<br \/>\n\u5728\u4e0b\u4e00\u4e2a\u7a97\u53e3\u4e2d\uff0c\u6211\u4eec\u5c06\u6dfb\u52a0\u6211\u4eec\u7684\u7528\u6237\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3118.jpg\" alt=\"alt text\" \/><\/p>\n<p>After that, we are going to expand the Logins folder, right-click on our user, and choose Properties. There, under UserMappings, we have to select the CompanyEmployee database and grant the dbwriter and dbreader roles.<br \/>\n\u4e4b\u540e\uff0c\u6211\u4eec\u5c06\u5c55\u5f00 Logins \u6587\u4ef6\u5939\uff0c\u53f3\u952e\u5355\u51fb\u6211\u4eec\u7684\u7528\u6237\uff0c\u7136\u540e\u9009\u62e9 Properties\u3002\u5728\u90a3\u91cc\uff0c\u5728 UserMappings \u4e0b\uff0c\u6211\u4eec\u5fc5\u987b\u9009\u62e9 CompanyEmployee \u6570\u636e\u5e93\u5e76\u6388\u4e88 dbwriter \u548c dbreader \u89d2\u8272\u3002<\/p>\n<p>Now, we can try to send the Authentication request:<br \/>\n\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u5c1d\u8bd5\u53d1\u9001 Authentication \u8bf7\u6c42\uff1a<\/p>\n<p><a href=\"http:\/\/www.companyemployees.codemaze\/api\/authentication\/login\">http:\/\/www.companyemployees.codemaze\/api\/authentication\/login<\/a><\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3119.jpg\" alt=\"alt text\" \/><\/p>\n<p>Excellent; we have our token. Now, we can send the request to the GetCompanies action with the generated token:<br \/>\n\u975e\u5e38\u597d;\u6211\u4eec\u6709\u6211\u4eec\u7684token\u3002\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u751f\u6210\u7684\u4ee4\u724c\u5c06\u8bf7\u6c42\u53d1\u9001\u5230 GetCompanies\u4f5c\uff1a<\/p>\n<p><a href=\"http:\/\/www.companyemployees.codemaze\/api\/companies\">http:\/\/www.companyemployees.codemaze\/api\/companies<\/a><\/p>\n<p><img decoding=\"async\" src=\"\/images\/ultimateaspnetcorewebapi6\/3120.jpg\" alt=\"alt text\" \/><\/p>\n<p>And there we go. Our API is published and working as expected.<br \/>\n\u597d\u4e86\u3002\u6211\u4eec\u7684 API \u5df2\u53d1\u5e03\u5e76\u6309\u9884\u671f\u5de5\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>31 DEPLOYMENT TO IIS 30 \u90e8\u7f72\u5230 IIS Before we start the deployment process, we would like to point out one important thing. We should always try to deploy an application on at least a local machine to somehow simulate the production environment as soon as we start with development. That way, we can observe how [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1160","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/1160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1160"}],"version-history":[{"count":0,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/1160\/revisions"}],"wp:attachment":[{"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}