小编Qur*_*tor的帖子

在ConfigureServices(aspnetcore)中获取wwwroot路径

在我的aspnetcore应用(v2.1)中,我需要配置一个〜/ wwwroot / App_Data / quranx.db中的只读数据库(entityframework核心+ SQLite)

我需要在Startup.ConfigureServices中调用此代码

services.AddDbContext<QuranXDataContext>(options => options
    .UseSqlite($"Data Source={databasePath}")
    .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
);
Run Code Online (Sandbox Code Playgroud)

但是到那时,我无法找到通往wwwroot的途径。要获得该路径,我需要IHostingEnvironment,但是直到Startup.Configure调用完成,即Startup.ConfigureServices完成后,我才能获得对该路径的引用。

怎么做?

c# asp.net-core

5
推荐指数
1
解决办法
2678
查看次数

标签 统计

asp.net-core ×1

c# ×1