我System.Timers.Timer在我的Asp.Net应用程序中使用a ,我需要使用HttpServerUtility.MapPath似乎只能通过的方法HttpContext.Current.Server.MapPath.问题是,HttpContext.Current是null的,当Timer.Elapsed事件触发.
是否有另一种方法来获取对HttpServerUtility对象的引用?我可以在我的类'构造函数中注入它.安全吗?如何确保在当前请求结束时不会收集垃圾?
谢谢!
在我的实体框架中,种子方法我有以下行来从不同的项目中获取文件:
var filePath = new DirectoryInfo(HostingEnvironment.ApplicationPhysicalPath).Parent.FullName + "\\Com.ProjectX\\companies.xls";
Run Code Online (Sandbox Code Playgroud)
这在HttpContext可用时有效,就像使用此操作方法触发它一样:
public ActionResult About()
{
var configuration = new Com.EntityModel.Configuration();
var migrator = new System.Data.Entity.Migrations.DbMigrator(configuration);
migrator.Update();
return View();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我Update-Database从包管理器控制台执行时它不起作用(找不到文件并且很难调试,因为我在执行此操作时也无法断点).
我希望能够使用Update-Database命令并让它在没有HttpContext的情况下工作.我怎样才能得到这条路?