gpt4 book ai didi

asp.net - 在 .NET 框架 SDK 风格的 web 项目中启动浏览器

转载 作者:行者123 更新时间:2023-12-04 04:20:21 26 4
gpt4 key购买 nike

我们将一些 web 项目更改为 SDK 样式,但是如果我们在 Visual Studio 中启动该项目,它将不会启动浏览器。 IISExpress 命令提示符会运行并启动网站,因此在手动访问网站时它可以工作。

使用 SDK 风格的项目时是否可以启动浏览器? (或者是否有解决方法/工具使其成为可能?)。我知道使用 dotnet 核心网站这确实有效,并且启动了一个新的浏览器实例,也许我们应该保留 .NET 框架 Web 项目的旧格式。

launchSettings.json

{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:29750/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\IIS Express\\iisexpress.exe",
"commandLineArgs": "/path:\"$(SolutionDir)$(ProjectName)\" /port:29750",
"launchBrowser": true,
"launchUrl": "/"
}
}
}

项目、删除的脚本和很少的 View
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<AssemblyName>Web</AssemblyName>
<OutputType>Library</OutputType>
<OutputPath>bin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Antlr" Version="3.5.0.2" />
<PackageReference Include="Castle.Windsor" Version="3.4.0" />
<PackageReference Include="Castle.Windsor.Mvc" Version="1.3.0" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNet.Web.Optimization" Version="1.1.3" />
<PackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Owino" Version="1.0.2" />
<PackageReference Include="SignalR.Castle.Windsor" Version="1.0.1" />
<PackageReference Include="Westwind.Globalization" Version="3.0.5" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup>
<Compile Remove="obj\**" />
<EmbeddedResource Remove="obj\**" />
<EntityDeploy Remove="obj\**" />
<None Remove="node_modules\**" />
<None Remove="fonts\**" />
<None Remove="obj\**" />
<None Remove="Scripts\dist\**" />
<None Remove="package-lock.json" />
<None Include=".babelrc" />
<None Include=".eslintignore" />
<None Include="package.json" />
<None Include="Views\Protocol\Index.cshtml" />
<None Include="Views\Settings\Index.cshtml" />
<None Include="Views\Shared\_Root.cshtml" />
<None Include="Views\Shared\_Shared.cshtml" />
</ItemGroup>


<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

信息
  • Visual Studio 2019 (16.4.2)
  • .NET 框架 4.6.1
  • IISExpress 启动并运行良好
  • 我可以手动访问该站点,但浏览器不会自动打开。
  • 最佳答案

    导入 System.Diagnostics 后,您可以在启动底部插入以下示例。

    Process.Start("chrome.exe", "https://google.com");

    关于asp.net - 在 .NET 框架 SDK 风格的 web 项目中启动浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59543356/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com