通常我会创建Web应用程序项目并使用代码隐藏,但我需要使用代码内联创建一个小的一次性演示应用程序. 我在应用程序中添加了一个global.asax文件,但由于一些奇怪的原因,Visual Studio 200
我在应用程序中添加了一个global.asax文件,但由于一些奇怪的原因,Visual Studio 2008 SP1不允许我编辑脚本标记之间的任何代码,即将代码添加到事件处理程序,如Application_Start,Session_Start.但是VS让我在脚本标签之外进行编辑.
这只是一个使用内置Web服务器的基于文件的简单Web应用程序.
有什么想法发生了什么?
这是代码内联global.asax VS创建:
<%@ Application Language="C#" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { // Code that runs on application startup } void Application_End(object sender, EventArgs e) { // Code that runs on application shutdown } void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs } void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started } void Session_End(object sender, EventArgs e) { // Code that runs when a session ends. // Note: The Session_End event is raised only when // the sessionstate mode // is set to InProc in the Web.config file. // If session mode is set to StateServer // or SQLServer, the event is not raised. } </script>好的,所以这里是答案:
您可以看到部分说明here和here.
基本上,global.asax文件实际上并没有被编译,因此VS2008提供了一个修复程序,以防止您修改它,因为您的修改将不起作用.