2.0: unexpected Application_Error

Discussion in 'ASP .Net' started by R.A.M., May 25, 2006.

  1. R.A.M.

    R.A.M. Guest

    Hello.
    I need your help in the following problem:
    I have ASP.NET application with starting page Default.aspx.
    On Default.aspx.cs page I have (.aspx contains no code):

    public partial class DefaultPage : System.Web.UI.Page
    {
    class DemoLogin : Login
    {
    public DemoLogin(string ID) : base()
    {
    this.ID = ID;
    DestinationPageUrl = "Welcome.aspx";
    TitleText = "<b>Logging in</b>";
    UserNameLabelText = "User";
    PasswordLabelText = "Password";
    PasswordRequiredErrorMessage = "Password required.";
    LoginButtonText = "Login";
    LoginButtonType = ButtonType.Button;
    RememberMeSet = true;
    RememberMeText = "Remeber";
    InstructionText = "<i>Enter any username and password
    \"demo\".</i>";
    FailureText = "Failure. Try again.";
    }
    override protected void OnAuthenticate(AuthenticateEventArgs
    e)
    {

    System.Diagnostics.Debug.WriteLine("DefaultPage.DemoLogin.OnAuthenticate()");
    e.Authenticated = (UserName != "" && Password == "demo");
    }
    }
    private void Page_Load(object sender, EventArgs e)
    {
    System.Diagnostics.Debug.WriteLine("DefaultPage.Page_Load()");
    Browser.Text = Request.Browser.Browser + " " +
    Request.Browser.Version;
    Platforma.Text = Request.Browser.Platform;
    Place.Controls.Add(new DemoLogin("Login"));
    Session["Users"] = Application["Users"];
    }
    }

    QUESTION: I don't understand why *after* Page_Load() I got a call to
    Application_Error(). I tried to debug, everything in Default.aspx.cs
    works fine.
    Here's my Global.asax:

    <%@ Application Language="C#" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Diagnostics" %>
    <script runat="server">
    void Application_Start(object sender, EventArgs e)
    {
    Debug.WriteLine("Application_Start()");
    Application["Users"] = 0;
    }
    void Application_End(object sender, EventArgs e)
    {
    Debug.WriteLine("Application_End()");
    Application["Users"] = 0;
    }
    void Application_Error(object sender, EventArgs e)
    {
    Debug.WriteLine("Application_Error()");
    Response.Redirect("Problem.html");
    }
    void Session_Start(object sender, EventArgs e)
    {
    Application.Lock();
    Application["Users"] = Convert.ToInt32(Application["Users"]) +
    1;
    Application.UnLock();
    Debug.WriteLine("Session_Start(): users: " +
    Application["Users"].ToString());
    }
    void Session_End(object sender, EventArgs e)
    {
    Application.Lock();
    Application["Users"] = Convert.ToInt32(Application["Users"]) -
    1;
    Application.UnLock();
    Debug.WriteLine("Session_End(): users: " +
    Application["Users"].ToString());
    }
    </script>

    Please help.
    Thank you very much.
    /RAM/
    R.A.M., May 25, 2006
    #1
    1. Advertising

  2. R.A.M.

    Jeff Dillon Guest

    Re: unexpected Application_Error

    What is the error?

    "R.A.M." <> wrote in message
    news:...
    > Hello.
    > I need your help in the following problem:
    > I have ASP.NET application with starting page Default.aspx.
    > On Default.aspx.cs page I have (.aspx contains no code):
    >
    > public partial class DefaultPage : System.Web.UI.Page
    > {
    > class DemoLogin : Login
    > {
    > public DemoLogin(string ID) : base()
    > {
    > this.ID = ID;
    > DestinationPageUrl = "Welcome.aspx";
    > TitleText = "<b>Logging in</b>";
    > UserNameLabelText = "User";
    > PasswordLabelText = "Password";
    > PasswordRequiredErrorMessage = "Password required.";
    > LoginButtonText = "Login";
    > LoginButtonType = ButtonType.Button;
    > RememberMeSet = true;
    > RememberMeText = "Remeber";
    > InstructionText = "<i>Enter any username and password
    > \"demo\".</i>";
    > FailureText = "Failure. Try again.";
    > }
    > override protected void OnAuthenticate(AuthenticateEventArgs
    > e)
    > {
    >
    > System.Diagnostics.Debug.WriteLine("DefaultPage.DemoLogin.OnAuthenticate()");
    > e.Authenticated = (UserName != "" && Password == "demo");
    > }
    > }
    > private void Page_Load(object sender, EventArgs e)
    > {
    > System.Diagnostics.Debug.WriteLine("DefaultPage.Page_Load()");
    > Browser.Text = Request.Browser.Browser + " " +
    > Request.Browser.Version;
    > Platforma.Text = Request.Browser.Platform;
    > Place.Controls.Add(new DemoLogin("Login"));
    > Session["Users"] = Application["Users"];
    > }
    > }
    >
    > QUESTION: I don't understand why *after* Page_Load() I got a call to
    > Application_Error(). I tried to debug, everything in Default.aspx.cs
    > works fine.
    > Here's my Global.asax:
    >
    > <%@ Application Language="C#" %>
    > <%@ Import Namespace="System" %>
    > <%@ Import Namespace="System.Diagnostics" %>
    > <script runat="server">
    > void Application_Start(object sender, EventArgs e)
    > {
    > Debug.WriteLine("Application_Start()");
    > Application["Users"] = 0;
    > }
    > void Application_End(object sender, EventArgs e)
    > {
    > Debug.WriteLine("Application_End()");
    > Application["Users"] = 0;
    > }
    > void Application_Error(object sender, EventArgs e)
    > {
    > Debug.WriteLine("Application_Error()");
    > Response.Redirect("Problem.html");
    > }
    > void Session_Start(object sender, EventArgs e)
    > {
    > Application.Lock();
    > Application["Users"] = Convert.ToInt32(Application["Users"]) +
    > 1;
    > Application.UnLock();
    > Debug.WriteLine("Session_Start(): users: " +
    > Application["Users"].ToString());
    > }
    > void Session_End(object sender, EventArgs e)
    > {
    > Application.Lock();
    > Application["Users"] = Convert.ToInt32(Application["Users"]) -
    > 1;
    > Application.UnLock();
    > Debug.WriteLine("Session_End(): users: " +
    > Application["Users"].ToString());
    > }
    > </script>
    >
    > Please help.
    > Thank you very much.
    > /RAM/
    Jeff Dillon, May 25, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ma_news

    Application_Error event

    ma_news, Jun 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    689
    ma_news
    Jun 17, 2004
  2. twahl
    Replies:
    2
    Views:
    618
    Tian Min Huang
    Jun 30, 2003
  3. Stoyan
    Replies:
    0
    Views:
    466
    Stoyan
    Jul 10, 2003
  4. Rad
    Replies:
    0
    Views:
    472
  5. Greg Burns
    Replies:
    1
    Views:
    6,310
Loading...

Share This Page