Home > Article > Backend Development > Steps to deploy ASP.NET Core project on IIS
This article mainly introduces the graphic method of deploying ASP.NET Core projects on IIS. Friends in need can refer to the following
Overview
Different from the ASP.NET era, ASP .NET Core is no longer hosted by the IIS worker process (w3wp.exe), but runs using a self-hosted web server (Kestrel). IIS acts as a reverse proxy and forwards requests to the ASP.NET Core program on different ports of Kestrel. , and then push the received request to the middleware pipeline. After processing your request and related business logic, the HTTP response data will be written back to IIS, and finally transferred to different clients (browsers, APP, client, etc.). The configuration files and processes will be slightly adjusted. The most important role in the middle is AspNetCoreModule, which is one of the IIS modules. After the request enters IIS, it will be forwarded by it immediately and quickly redirected to the ASP.NET Core project. So at this time we do not need to set up an application pool to host our code, it is only responsible for forwarding requests.
Before deploying, make sure that the AspNetCoreModule hosting module has been installed on your IIS. If not, click here to download and install it
一, Install IIS
1. Go to Control Panel → Programs → Enable or turn off Windows features → Check the IIS Management Console under Internet Information Services and Web Management Tools
2. Publish the project
1. Publish the ASP.NET Core API project we built in the previous article, then select IIS and create a new publishing configuration
2. Select the file system for the publishing method, and then set a publishing path
3. The configuration file can be customized according to your online , choose the offline environment, because it is based on .NET Core, so the target framework is netcoreapp1.1, then save and publish
4. Of course, you also You can publish based on the Publish command of the CLI. Just switch to the Light.API root directory and enter the following command.
dotnet publish --framework netcoreapp1.1 --output "E:\Publish" --configuration Release
framework means the target framework, and output means to publish To the directory folder, configuration represents the configuration file, which is equivalent to the operation we published through the manager above, as shown in the figure:
3. In IIS Add a website
1. Add a website, set the name, and point the path to the folder you just published, and then start the website
2. Set the .NET CLR version of the application pool to "No managed code", because as mentioned just now, IIS acts as a reverse proxy and does not need it to host code
3. OK, you’re done, browse our website.
My heart is broken at this time. There is no useful prompt information. It seems that I can only check the running log of the application myself
4. Set the logging method of IIS to log files and ETW events
5. Re-visit the website, and then open the Windows application log, you will see a message like this. This means that your application has been started by the process with PID 3236 and is listening on port 25636.
I opened the task manager and checked, and it was right. Everything should be normal, so why is it 404 when accessing the website?
After struggling for a long time, it turned out that the website did not automatically redirect to the /swagger/ui page. Re-visit: http://192.168.1.105/swagger/ui, you You will see a familiar screen
6. Finally, you can actually run the program you published through CLI, switch to your publishing folder, and enter the following command :
dotnet Light.API.dll
If you see this prompt, it means you are successful. Try visiting: http://localhost:5000/swagger/ui
At this time, if you look back at the task manager, there will be another dotnet process
Write it at the end
At this point, the entire IIS setup has been completed. I wonder if you have gained anything. Next, I don’t know what kind of pitfalls there will be when publishing it on Linux. No matter what, every step you take will be worth it when you look back!
The above is the detailed content of Steps to deploy ASP.NET Core project on IIS. For more information, please follow other related articles on the PHP Chinese website!