编辑:我设法使用有效证书通过 IIS 运行此程序,但我还没有找到放弃新代理方法的方法。如果您想了解有关使用 IIS 而不是 IIS Express 的一些信息,请跳至结尾。
简而言之:使用最新的 ASP.NET 6 和 Angular 模板 (Visual Studio 2022),如何绕过反向代理并使用与以前版本的 .NET 相同的方法?我不想通过 SPA URL 运行应用程序,并将后端请求转发到 SPA 代理。
详细来说,我的目标:
我想导航到https://mydomain.local并让它为所有内容提供服务,这在 .NET 6 之前不是问题。您可以使用UseProxyToSpaDevelopmentServer、运行npm start,一切都很好。
尽管我知道您仍然可以使用它,但 .NET 6 放弃了它Startup.cs,并且指南建议继续使用简化版Program.cs。
我努力了:
aspnetcore-https.js)proxy.conf.js通过删除 proxyConfig 属性来摆脱代理配置 ( )angular.json不幸的是,对以前版本的建议不起作用 如何在 asp.net core 3 中添加全局路由前缀?
app.UsePathBase(new PathString("/api"));
Run Code Online (Sandbox Code Playgroud)
也不是这个
public static class MvcOptionsExtensions
{
public static void UseGeneralRoutePrefix(this MvcOptions opts, IRouteTemplateProvider routeAttribute)
{
opts.Conventions.Add(new RoutePrefixConvention(routeAttribute));
}
public static void UseGeneralRoutePrefix(this MvcOptions opts, string
prefix)
{
opts.UseGeneralRoutePrefix(new RouteAttribute(prefix));
}
}
Run Code Online (Sandbox Code Playgroud) 在Startup.cs我添加api/到我的路线模式的开始。
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "api/{controller}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
但它没有做任何事情:旧的 URL 继续工作,并且以 return 404 开头的 URL 继续工作。/api这没有任何意义!
如何让我的 API 在 下提供服务/api?