gpt4 book ai didi

c# - AspNetCore 设置内容根路径

转载 作者:行者123 更新时间:2023-12-04 01:37:24 25 4
gpt4 key购买 nike

怎么改Content root path在应用程序 .Net Core 3.0 ASP Blazor 上启动?
现在应用程序以输出开始

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\Art\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
!!! C:\Program Files\WindowsApps\6c2bb0ad-5956-4886-9e3f-2135ebe50d2f_1.0.8.0_x64__n37t8n8dtxdg6\TUTDF_Viewer_v2\
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Windows\system32

我要换 Content root path来自 C:\Windows\system32到应用程序初始化的另一条路径。

如何更改 Content root path在 AspNetCore 应用程序上启动?

最佳答案

最正确的方法是更改​​项目的Program.cs——添加

var p = System.Reflection.Assembly.GetEntryAssembly().Location;
p = p.Substring(0, p.LastIndexOf(@"\") + 1);
webBuilder.UseContentRoot(p);

CreateHostBuilder .

完整示例:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
var p = System.Reflection.Assembly.GetEntryAssembly().Location;
p = p.Substring(0, p.LastIndexOf(@"\") + 1);

webBuilder.UseContentRoot(p);
webBuilder.UseStartup<Startup>();
});

关于c# - AspNetCore 设置内容根路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59033413/

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