WebActivator。preApplicationStartMethod不起作用 [英] WebActivator.PreApplicationStartMethod does not work
问题描述
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyApp.App_Start.StructureMapMvc), "Start")]
namespace MyApp.App_Start
{
public static class StructureMapMvc
{
public static void Start()
{
var container = IoC.Initialize();
DependencyResolver.SetResolver(new SmDependencyResolver(container));
}
}
}
下面是我的code是应该在Global.asax中的Application_Start之前运行。
我升级我的web项目从MVC 3至4 MVC所以,在这个过程中,我在命名空间中犯了一个错误。这之前,我纠正了我的工作空间。它不再起作用了。我重置IIS /冲洗DNS /重建解决方案/删除在C .NET临时文件:\\ WINDOWS \\ Microsoft.NET \\ Framework64 \\ versionxxxxxx ... \\临时ASP.NET文件\\根。
毫无效果。我失去了一些东西?初始化()方法有我所有的结构图的东西依赖解析的东西。所以,我不能前进没有搞清楚了这一点。试图诊断问题这么多小时,我需要帮助。
Here is my code that is supposed to run before Application_start in global.asax. I was upgrading my web project from mvc 3 to mvc 4. So, In that process, I made a mistake in namespace. This was working before i corrected my namespace. It no longer works now. I reset iis/flushed dns/ rebuilt solution/removed the temporary .net files in C:\Windows\Microsoft.NET\Framework64\versionxxxxxx...\Temporary ASP.NET Files\root. Nothing worked. Am i missing something here? The Initialize() method has all my structure map stuff dependency resolution stuff. So, I can't move forward without figuring this out. Tried to diagnose the problem for so many hours and i need help.
推荐答案
如果你的code是在网站项目(即下APP_ code文件夹),你不能使用的 preApplicationStartupMethod 的!您可以使用的 PostApplicationStartupMethod 的代替。在pre的方法的Global.asax之前执行* *的Application_Start运行,而邮报之后执行。
If your code is in a Web Site Project (ie, under the App_Code folder) you cannot use PreApplicationStartupMethod! You can use PostApplicationStartupMethod instead. The "Pre" method executes before global.asax *Application_Start* runs, while "Post" executes after.
我浪费了一个很好的两个小时我想通了这一点之前,所以希望这会帮助别人避免!
I wasted a good hour or two before I figured this out, so hopefully this will help someone else avoid that!
这篇关于WebActivator。preApplicationStartMethod不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!