2011-06-13 6 views
3

asp.net 응용 프로그램에 대한 global.asax 파일을 만들었습니다. session_start 메서드에서 일부 코드를 실행합니다. 코드가 실행되지 않습니다. asp.net 2.0에서 global.asax 파일을 사용하는 절차가 있습니까?asp.net - 2.0 asp.net 응용 프로그램에 대한 global.asax

나는 asax 파일 자체와 코드 숨김 파일을 가지고있다.

감사합니다.

편집 : asax 파일 : 파일 뒤에

<%@ Application Codebehind="Global.asax.cs" Inherits="GrowUp.Global" %> 

코드 :

using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Web; 
using System.Web.SessionState; 
namespace Ligdol 
{ 
/// <summary> 
/// Summary description for Global. 
/// </summary> 
public class Global : System.Web.HttpApplication 
{ 
    /// <summary> 
    /// Required designer variable. 
    /// </summary> 
    private System.ComponentModel.IContainer components = null; 

    public Global() 
    { 
     InitializeComponent(); 
    } 

    protected void Application_Start(Object sender, EventArgs e) 
    { 
     Application["HostName"] = System.Configuration.ConfigurationSettings.AppSettings["HostName"]; 
     Application["counter"] = 1; 
    } 

    protected void Session_Start(Object sender, EventArgs e) 
    { 
     // Get the count from the application variable 
    int counter = int.Parse(Application["counter"].ToString()); 
    //Check if a cookie exists. 
    if(HttpContext.Current.Request.Cookies["ligdolVersion"] != null) 
    { 
     //If a cookie exists, we need to redirect the user to the respective site. 
     if(HttpContext.Current.Request.Cookies["ligdolVersion"].ToString() == "new") 
     { 
      Response.StatusCode = 302; 
      Response.Status = "Moved temporarily"; 
      Response.Redirect("http://beta.ligdol.co.il"); 
      return; 
     } 
     else if(HttpContext.Current.Request.Cookies["ligdolVersion"].ToString() == "old") 
     { 
      return; 
     } 
    } 
    else if (counter == 40) 
    { 
     // If a cookie does not already exist, 
     //we need to check if the user is to be allowed to continue to the old site 
     //or be redirected to the new site. 


     //Note in a file that a user was redirected, so we can get an estimate of how many are being redirected. 
     System.IO.TextWriter tw = new System.IO.StreamWriter(@"redirect.log"); 
     tw.WriteLine("Redirected to new site."); 
     tw.Close(); 
     // Reset counter. 
     Application["counter"] = 1; 
     //write cookie made to expire in 30 days, by then the experiment will be over (we hope!). 
     HttpCookie cookie = new HttpCookie("ligdolVersion"); 
     DateTime dtNow = DateTime.Now; 
     TimeSpan tsSpan = new TimeSpan(30, 0, 0, 0, 0); 
     cookie.Expires = dtNow + tsSpan; 
     cookie.Value = "new"; 
     Response.Cookies.Add(cookie); 
     Response.Redirect("http://beta.ligdol.co.il"); 
     return; 
    } 
    else 
    { 
     System.IO.TextWriter tw = new System.IO.StreamWriter(@"redirect.log"); 
     tw.WriteLine("Redirected to old site."); 
     tw.Close(); 
     HttpCookie cookie = new HttpCookie("ligdolVersion"); 
     DateTime dtNow = DateTime.Now; 
     TimeSpan tsSpan = new TimeSpan(30, 0, 0, 0, 0); 
     cookie.Expires = dtNow + tsSpan; 
     cookie.Value = "old"; 
     Response.Cookies.Add(cookie); 
     return; 
    } 

    } 

    protected void Application_BeginRequest(Object sender, EventArgs e) 
    { 

    } 

    protected void Application_EndRequest(Object sender, EventArgs e) 
    { 

    } 

    protected void Application_AuthenticateRequest(Object sender, EventArgs e) 
    { 

    } 

    protected void Application_Error(Object sender, EventArgs e) 
    { 

    } 

    protected void Session_End(Object sender, EventArgs e) 
    { 

    } 

    protected void Application_End(Object sender, EventArgs e) 
    { 

    } 

    #region Web Form Designer generated code 
    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    {  
     this.components = new System.ComponentModel.Container(); 
    } 
    #endregion 
} 

}

+1

시도해 본 코드를 게시 할 수 있습니까? –

+0

물론입니다. 죄송합니다. 아마도 asp.net 2.0에 global.asax 파일과 관련된 몇 가지 알려진 문제가 있다고 생각했습니다. 원본 게시물에 게시 된 코드. –

+0

Global.asax에 중단 점을 추가 했습니까? –

답변

1

문제는 코드 숨김 파일이었다. 일단 asax 파일 안에 코드 인라인을 넣으면 작동했습니다. 이것은 오래된 웹 사이트 프로젝트를위한 유일한 솔루션 일 것입니다.

관련 문제