Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2007, 05:24 AM
Authorized User
 
Join Date: Jan 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default Context.clearerror() gives an error in Global.asax

I have added a Global.asax.cs in the App_code folder and this file looks like this

public class Global : System.Web.HttpApplication
{
    private static ILog ms_logger = LogManager.GetLogger(typeof(Global));
    private System.ComponentModel.IContainer components = null;

    public Global()
    {
        InitializeComponent();
    }

    protected void Application_Start(object sender, EventArgs e)
    {
        log4net.Config.DOMConfigurator.Configure();
    }

    protected void Application_End(object sender, EventArgs e)
    {
    }

    protected void Application_Error(object sender, EventArgs e)
    {
        Exception ex = Server.GetLastError();
        ms_logger.Error(ex.Message, ex);
        if(Context!=null)
            Context.ClearError();
        ms_logger.Debug("Forwarding to ErrorPage.aspx");
        Response.Redirect(AppConstants.ERROR_URL, true);
    }

    protected void Session_Start(object sender, EventArgs e)
    {
        ms_logger.Debug("Starting new session");
    }

    protected void Session_End(object sender, EventArgs e)
    {
        Response.Redirect(AppConstants.LOGOUT_URL, true);
    }

    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
    }

And in the web.config file i have added the session state as inpoc and it looks like this

<sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false"
            timeout="1">
        </sessionState>

wantedly i have configured timeout to 1 min.
after one min i am getting error in global.asax.cs near the context.clearall but i added if context!=null and it was fine now i am getting near Response.Redirect(AppConstants.ERROR_URL, true),
but the same code worked in the 1.1 application and when session times out it takes me to logout page but in 2.0 its not happening remaining in the same page after session timeout.

Can anyone help me out to solve this problem or tell me an alternate solution to take to logout page after session expires.

__________________
Regards,
P.Madhusudhana Rao
 
Old April 9th, 2007, 03:21 PM
Authorized User
 
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,

I have a simliar problem. I have a projec in ASP.Net2.0 and i added Global.asax file by right clicking on root folder and Add new items and add Global.asax file. Here is the syntax of Global.aspx file i have.

<%@ Application Language="C#" Inherits="Global" %>
<script Language="C#" runat="server">
    void Application_Start(object sender, EventArgs e)
    {
    }
    void Application_End(object sender, EventArgs e)
    {
     }
    void Application_Error(object sender, EventArgs e)
    {
    }
    void Session_Start(object sender, EventArgs e)
    { Conversion _session = new Conversion();
        Session["Started"] = true;
    }
    void Session_End(object sender, EventArgs e)
    {
         }

</script>
 When I debug my project the control simply by pass Global file and goes straight to class file where i try to retrieve the value of Session variable to find out which mode it is in.

I dont understand what the problem is. I also have same code in we.conifg
<sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false"
            timeout="20"
    />

It looks like Parser doesnt even know that Global.asax file is there. I am learning ASP.Net 2.0 , so cant figure this out. Please HELP!

Thanks in advance
Kamal

 
Old April 10th, 2007, 05:13 AM
Authorized User
 
Join Date: Jan 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try adding gobal.asax.cs file in the app_code folder

 
Old April 10th, 2007, 07:43 AM
Authorized User
 
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

NOw here is the question. When i add Global.asax only.asax file is added. Do i have to externally create global.asax.cs file and then relate them. This could be very simple question but i am confused.

Thanks a lot.

 
Old April 10th, 2007, 08:09 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You might not be able to *see* the global.asax.cs file in the IDE. Some times the nested files are hidden (not just collapsed under their parent).

Look for the "Show all files" button in the solution explorer.

-Peter
 
Old April 10th, 2007, 08:20 AM
Authorized User
 
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried that. I dont see any Global.aspx.cs file. That is whole point of confusion for me. Either i am dumb enough or there is something new i dont know about.

Thanks for your time and help.I really appreciate that.

 
Old April 12th, 2007, 02:12 AM
Authorized User
 
Join Date: Jan 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In 2.0 we dont get the global.asax.cs file automatically under the App_code u have to add the cs class with file name global.asax.cs and write the functions u want to do in that file which acts as codebehind file for global.asax...







Similar Threads
Thread Thread Starter Forum Replies Last Post
an error in Global.asax when the page is started lovehorse BOOK: ASP.NET Website Programming Problem-Design-Solution 5 October 17th, 2006 07:22 PM
Global.asax error sivaganesh_naidu ASP.NET 2.0 Professional 2 August 24th, 2006 10:53 AM
Error with Global.asax madkaikar_ashish .NET Web Services 3 August 7th, 2006 12:03 AM
global.asax parser error exarkuun General .NET 3 February 24th, 2005 01:56 AM
An Error in Global.asax! Action BOOK: ASP.NET Website Programming Problem-Design-Solution 5 December 23rd, 2004 12:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.