asp.net, spa 项目无法访问 swagger , asp.net单独启动
报错信息
访问swagger的报错如下: http://localhost:5119/swagger, 大概就是说swagger被spa的中间件拦截了。
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HNBBVVF3U15P", Request id "0HNBBVVF3U15P:00000003": An unhandled exception was thrown by the application.
System.UriFormatException: Invalid URI: The URI is empty.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
at System.Uri..ctor(String uriString)
at Microsoft.AspNetCore.SpaProxy.SpaProxyMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Hosting.HostingApplication.ProcessRequestAsync(Context context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
项目中的spa被注释掉了
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!-- spa page set up -->
<!-- <SpaRoot>..\longforcecocweb.client</SpaRoot> -->
<!-- <SpaProxyLaunchCommand>npm run dev</SpaProxyLaunchCommand> -->
<!-- <SpaProxyServerUrl>https://localhost:5173</SpaProxyServerUrl> -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy">
<Version>6.*-*</Version>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
launchSettings.json中
需要将👇所指示的一行删除
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:4067",
"sslPort": 44306
}
},
"profiles": {
"LongforceCocWeb.Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7224;http://localhost:5119",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
// 👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
}
}
}
浙公网安备 33010602011771号