You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行Angular-CLI .NET应用时为何启动两个IIS Express服务器?

Why Two IIS Express Servers Run for Your .NET Core + Angular CLI Project

Great question—let’s break down exactly what’s happening here, including the role of that AngularCliServer middleware you suspected.

1. What Each Server Does

Let’s start with the two instances you’re seeing:

  • https://localhost:44375 (your browser’s target)
    This is your primary ASP.NET Core backend server, hosted via IIS Express. It’s the main entry point because:

    • It runs all your .NET Core Web API, server-side logic, and handles authentication/authorization.
    • In development mode, it acts as a reverse proxy for the second server, routing all client-side Angular requests to it.
    • When you publish for production, this server will serve the compiled Angular static files directly, no second server needed.
  • http://localhost:52629
    This is the Angular CLI development server, wrapped in an IIS Express instance by Visual Studio. Its sole job is to handle Angular’s development workflow:

    • Compile your TypeScript code to JavaScript in real time.
    • Enable hot module replacement (HMR) so your browser updates instantly when you edit Angular files.
    • Serve uncompiled Angular assets (like templates, styles, and bundles) during development.

2. The AngularCliServer Middleware’s Role

You were spot-on to connect this to AngularCliServer—it’s the glue between the two servers. Here’s how it works in your project’s Startup.cs:

  • In the Configure method, the template checks if you’re running in development mode.
  • If yes, the middleware automatically starts the Angular CLI server (the second IIS Express instance) if it isn’t already running.
  • It then proxies all client-side requests (think index.html, Angular bundle files, etc.) from the ASP.NET Core server to the Angular CLI server.
  • This is why you only need to navigate to the ASP.NET Core URL—your browser never directly hits the Angular server; the backend handles the routing seamlessly.

You can see this logic in action by checking your Startup.cs file—look for code like this:

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseAngularCliServer(npmScript: "start");
}

3. Why Visual Studio Uses Two IIS Express Instances

This setup is all about making your development workflow smoother and more consistent:

  • Isolating the backend and frontend servers means you can debug .NET Core code without disrupting Angular’s hot reload, and vice versa.
  • Using IIS Express for both ensures routing and security (especially HTTPS for the backend) aligns with how you’d deploy the app to production.
  • Visual Studio’s integration wraps the Angular CLI server in IIS Express to keep all your debugging tools (like breakpoints in both .NET and Angular code) in one place.

If you want to confirm this, take a look at your project’s Properties/launchSettings.json—you’ll find configurations that define how both servers are launched and how requests are proxied between them.


内容的提问来源于stack exchange,提问作者Unknown developer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:03:58