相关疑难解决方法(0)

如何在线程或计时器中访问HttpServerUtility.MapPath方法?

System.Timers.Timer在我的Asp.Net应用程序中使用a ,我需要使用HttpServerUtility.MapPath似乎只能通过的方法HttpContext.Current.Server.MapPath.问题是,HttpContext.Currentnull的,当Timer.Elapsed事件触发.

是否有另一种方法来获取对HttpServerUtility对象的引用?我可以在我的类'构造函数中注入它.安全吗?如何确保在当前请求结束时不会收集垃圾?

谢谢!

.net asp.net timer httpcontext

88
推荐指数
3
解决办法
4万
查看次数

如何在没有HttpContext的Entity Framework Seed方法中获取文件路径(从包管理器命令执行)

在我的实体框架中,种子方法我有以下行来从不同的项目中获取文件:

 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的情况下工作.我怎样才能得到这条路?

entity-framework ef-code-first

2
推荐指数
1
解决办法
1487
查看次数