반응형
Global.asax.cs 파일은 어디에 있습니까?
VS 2008을 사용하고 있습니다.파일->신규->웹사이트->Asp.net 웹사이트에서 새로운 Asp.net 웹사이트 프로젝트를 만들었습니다.
이제 Global.asax와 .cs 파일을 프로젝트에 추가하려고 합니다.프로젝트 ->새 항목 추가 ->글로벌 응용프로그램 클래스를 마우스 오른쪽 단추로 클릭합니다.그런 다음 추가 버튼을 클릭했습니다.
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>
이것으로 괜찮습니다.하지만 Global.asax.cs 파일은 어디에 있습니까?
감사해요.
정상적으로 생성되지 않으므로 사용자가 직접 추가해야 합니다.
추가 후Global.asax
타고
- 웹사이트 우클릭 -> 새 항목 추가 -> 글로벌 응용프로그램 클래스 -> 추가
클래스를 추가해야 합니다.
- App_Code -> 신규 아이템 추가 -> Class -> name it Global.cs -> Add
새로 생성된 상속인System.Web.HttpApplication
생성된 모든 메소드를 복사합니다.Global.asax
로.Global.cs
상속 특성을 Global.asax 파일에 추가합니다.
Global.asax는 다음과 같이 표시됩니다.
<%@ Application Language="C#" Inherits="Global" %>
Global.cs 의App_Code
다음과 같이 표시됩니다. -
public class Global : System.Web.HttpApplication
{
public Global()
{
//
// TODO: Add constructor logic here
//
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
/// Many other events like begin request...e.t.c, e.t.c
}
웹 응용 프로그램 대신 웹 사이트를 만들었기 때문입니다.cs/vb
파일은 웹 응용 프로그램에서만 볼 수 있지만 웹 사이트에서는 별도로 볼 수 없습니다.cs/vb
파일.
편집: 웹 사이트에서 다음과 같은 acs 파일 동작을 추가할 수 있습니다.
<%@ Application CodeFile="Global.asax.cs" Inherits="ApplicationName.MyApplication" Language="C#" %>
~/Global.asax.cs:
namespace ApplicationName
{
public partial class MyApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
}
}
}
언급URL : https://stackoverflow.com/questions/6288209/where-is-the-global-asax-cs-file
반응형
'programing' 카테고리의 다른 글
PL/SQL에서 RECORD 컬렉션을 수동으로 초기화하는 방법은 무엇입니까? (0) | 2023.08.14 |
---|---|
실행할 참조 어셈블리를 로드할 수 없습니다. (0) | 2023.08.14 |
탐색 컨트롤러에서 두 개의 보기를 동시에 팝업하려면 어떻게 해야 합니까? (0) | 2023.08.14 |
jquery, 도메인, URL 가져오기 (0) | 2023.08.14 |
다음은 무엇을 의미합니까:accept-encoding? (0) | 2023.08.14 |