在global.asax中未调用Application_Start.为什么? [英] Application_Start not called in global.asax. Why?

查看:143
本文介绍了在global.asax中未调用Application_Start.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的global.asax中,我有以下代码:

public static bool Was = false;

protected void Application_Start(object sender, EventArgs e)
{
    Was = true;
}

当我打开页面并查看Was变量时,它仍然是false.是什么赋予了? (注意:该变量未在其他任何地方使用,我只是在此测试用例中使用了它)

更新:我刚刚发现我的整个global.asax文件被忽略了.怎么会这样?

更新2:抱歉,它确实可以发挥作用.但是那里还有额外的怪异之处.如此多的怪异之处,我打开了一个新问题那个.

解决方案

好,所以问题是我没有安装我的应用程序所需的Visual J#redist.但是,这个问题的表现确实很奇怪.我为此提出了另一个问题:

.net何时检查程序集依赖项?

从本质上讲,我猜得出的教训是:当您的应用程序缺少某些依赖程序集时,不要指望它会彻底失败.期待一些方法调用开始抛出FileNotFoundException.

In my global.asax I have the following code:

public static bool Was = false;

protected void Application_Start(object sender, EventArgs e)
{
    Was = true;
}

When I open a page and look at the Was variable, it's still false. What gives? (Note: the variable isn't used anywhere else, I made it just for this test case)

Update: I just found out that my whole global.asax file is getting ignored. How can this be?

Update 2: Sorry, it does get into play after all. But there's extra weirdness there. So much extra weirdness, that I've opened a new question for that.

解决方案

OK, so the problem was that I had not installed Visual J# redist which is required by my app. However the manifestation of this problem was really weird. I've opened another question for that:

When does .net check for assembly dependencies?

In essence I guess the lesson is: when your application lacks some dependant assembly, don't expect it to fail outright. Expect some method calls to start throwing FileNotFoundException.

这篇关于在global.asax中未调用Application_Start.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆