通常、私は Web アプリケーション プロジェクトを作成し、コード ビハインドを使用しますが、コード インラインを使用して小さな使い捨てのデモ アプリを作成する必要があります。
アプリに global.asax ファイルを追加しましたが、何らかの理由で、Visual Studio 2008 SP1 ではスクリプト タグ間のコードを編集できません。つまりApplication_Start
、Session_Start
. ただし、VS では script タグの外側で編集できます。
これは、組み込みの Web サーバーを使用する単純なファイル ベースの Web アプリです。
何が起こっているのですか?
これは、VS が作成するコード インライン global.asax です。
<%@ 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>