如何更改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>();
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句