的Application_Start不工作 [英] Application_start not working

查看:340
本文介绍了的Application_Start不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一些code。在的Application_Start在我的的Global.asax 文件()方法。当我部署我在应用程序IIS 服务器不会被调用。在code是可访问的,当我在.NET Framework上运行它。

I have written some code in the application_start() method in my global.asax file. It does not get called when I deploy my application on IIS server. The code is accessible when I run it in the .NET framework.

我试图重新启动应用程序很多次,但它仍然没有工作。

I've tried to restart the application many times, but it's still not working.

我也试着从以下链接的建议。

I've also tried the suggestion from the following link.

的Application_Start不烧?

推荐答案

有你需要知道之前,你试图调试 Appplication_Start 几件事情。有 -

There are few things you need to know before you are trying to debug Appplication_Start. There are -

一:当code执行,为什么它是几乎不可能通过附加到它调试

在应用程序池启动,您的网站正在启动首次被执行的应用程序启动方法。如果部署新的交付到IIS,那么IIS可能会重新启动它自己,但不能保证它会的。因此,在部署新的codeS并不能保证它会重新启动池,他执行的应用程序启动。你应该重新启动应用程序池,以保证执行的应用程序启动。

The application start method is executed when the application pool starts and your website is being started up for the first time. If you deploy new deliverables to IIS, then IIS might restart it itself, but there is no guarantee that it will. So, deploying new codes does not guarantee that it will restart the pool and he execution of application start. You should restart your application pool to guarantee execution of application start.

在调试的IIS应用程序时,Visual Studio将自己附着到一个名为的w3wp.exe similart一个过程或东西(我忘记了实际的可执行文件的名称),这是工作进程和唯一可用后,记住后,您的应用程序池是和你的网站了。因此,换句话说,如果你是在服务列表中看到这一点,那么该应用程序开始已经执行,附加到它不会给你一个机会,调试。这是一种战争与时间的拉锯战中。

While debugging IIS applications, Visual Studio attaches itself to a process something named w3wp.exe or similart (I forgot the actual executable name), which is the worker process and only available after, remember after, your application pool is up and your site is up. So, in other words, if you are seeing this in service list, then the application start has already been executed and attaching to it will not give you a chance to debug it. It is kind of a tug of war with time.

所以,换句话说,它是调试应用程序启动的一种不可能的,除非你是非常非常快的。

So, in other words, it is kind of impossible to debug application start unless you are very very quick.

二,解决方案1 ​​ - 通过开发服务器

推出的Visual Studio与Asp.net开发服务器或IIS EX preSS您的应用程序,那么你就可以调试。但是,如果你真的想在IIS上进行调试,然后检查下一节

Launch your application in visual studio with Asp.net development server or IIS express, then you will be able to debug. But if you really want to debug on IIS, then check the next section

二,解决方案2 - 在IIS

有一个在名称 System.Diagnostics程序调试库,它有一个很好的方式来调用调试器在code。你可以在这里阅读 - 的http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break(v=vs.110).aspx

There is a library in the name System.Diagnostics, Debuggerand it has a nice way to call debugger in code. You can read it here - http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break(v=vs.110).aspx

修改你的应用程序启动本 -

Modify you application start with this -

public void Application_Start(){
    ....... //other codes
    Debugger.Break() or Debugger.Launch()
}

在这行执行,IIS将停止执行,并会告诉你一个调试器选择窗口(类似附一),让您的解决方案打开VS,然后选择VS从列表中,将能够调试像往常一样...:)

When this line executes, IIS will halt execution, and will show you a debugger selector window (similar to the one attached), keep your solution open in vs and select that vs from the list, will be able to debug as usual... :)

如果你使用的是Windows 8和调试程序未启动,读这篇文章,使之 -

In case you are using windows 8 and the debugger does not launch, read this article to enable it -

<一个href="http://blogs.msdn.com/b/mapo/archive/2013/11/07/debugger-launch-not-displaying-jit-debugger-selection-popup-on-windows-8-8-1.aspx" rel="nofollow">http://blogs.msdn.com/b/mapo/archive/2013/11/07/debugger-launch-not-displaying-jit-debugger-selection-popup-on-windows-8-8-1.aspx

三:一个很重要的事情

我注意到,你说,你是在的Application_Start添加数据库条目。你应该记住,的Application_Start不具有的HttpContext ViewContext ,所以你的数据库访问code可能会失败,那么许多其他原因。

I noticed that you said, you are adding db entries in Application_Start. You should keep in mind that, Application_Start does not have a HttpContext, ViewContext, So your db access code may fail for so many others reasons.

这篇关于的Application_Start不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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