Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 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 Professional 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
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 25th, 2007, 04:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default Session issue with VWD

Hello,

I have an odd issue with VWD, though I don't know that is is specific to VWD. I have some code in a Global.asax file that sets a custom princial object for the session in the Application_AcquireRequestState event.

When I run the app (CSLA's PTWeb) in VWD, the code breaks in the Application_AcquireRequestState event at this (the first) line:

 
Code:
if (Session["CSLA-Principal"] != null)


The error is:

Code:
Session state is not available in this context.
However, the program compiles correctly and when I launch it in IE, it runs correctly too. Perfectly.

Anyone ever encounter anything like this? The app won't run in VWD because a Session object isn't instantiated (apparently) at the time the Application_AcquireRequestState event fires, but the compiled app runs fine on IIS and in IE. Should also mention I didn't have this problem running the app in .NET 1.1/VS 2003. The Global.aspx event fired fine and set the CurrentPrincipal.

Hmm...

Is the Session object not available at this point under .Net 2.0 or something weird like that?

Thanks as always,

Bob

My Global.asax event:

Code:
public class Global : System.Web.HttpApplication 
{

    public Global()
    {
        InitializeComponent();
    }



    protected void Application_AcquireRequestState(Object sender, EventArgs e)
    {
        // set the security principal to custom BusinessPrincipal
        if (Session["CSLA-Principal"] != null)
        {
            Thread.CurrentPrincipal = (IPrincipal)Session["CSLA-Principal"];
            HttpContext.Current.User = Thread.CurrentPrincipal;
        }
        else
        {
            if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                System.Web.Security.FormsAuthentication.SignOut();
                Server.Transfer("Login.aspx");
            }
        }
    }

    private void InitializeComponent()
    {

        this.AcquireRequestState += new System.EventHandler(this.Application_AcquireRequestState);

    }
}
  #2 (permalink)  
Old December 25th, 2007, 05:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

BUT...when I run the app in Debug...

The code breaks at
Code:
if (Session["CSLA-Principal"] != null)
sometimes. If it does break here, it cycles back through this line of code a couple of times until, apparently, session state IS available.

EVENTUALLY, the session state becomes available, and the app proceeds correctly. I get the same behavior on subsequent page requests.

It almost like there is a delay in initializing session state, and when I run the app in debug mode, app processing slows down enough to allow session state to be initialized? I'm just reaching here. But have no idea what else could be going on. Any thoughts?

Bob




  #3 (permalink)  
Old December 25th, 2007, 05:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Oh, and...

This is largely immaterial to the behavior I'm asking about, but I went back to a .NET 2.0 style Global.asax page. Don't know why after inventing CodeBehind MS reverted to in-line script for just these pages, but here it is:

Code:
<%@ Application Language="C#" %>

<script 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){} 
    void Session_End(object sender, EventArgs e){} 
    protected void Application_AcquireRequestState(Object sender, EventArgs e)
    {

        // set the security principal to custom BusinessPrincipal
        if (Session["CSLA-Principal"] != null)
        {
            System.Threading.Thread.CurrentPrincipal = (System.Security.Principal.IPrincipal)Session["CSLA-Principal"];
            HttpContext.Current.User = System.Threading.Thread.CurrentPrincipal;
        }
        else
        {
            if (System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                System.Web.Security.FormsAuthentication.SignOut();
                Server.Transfer("Login.aspx");
            }
        }
    }

</script>
Bob

  #4 (permalink)  
Old December 26th, 2007, 04:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

I guess this issue is pretty much resolved. Seems like i can just F-11 through it until session state catches up. Good enough for me.

Bob

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Related Issue asmii Beginning PHP 3 October 5th, 2008 07:07 PM
C # or ASP Used in VWD ? vinu123 ASP.NET 2.0 Basics 2 December 18th, 2006 01:25 AM
Session time out issue sameer_chandra Pro VB 6 1 July 31st, 2006 11:29 AM
Session & secuirty issue of shopping cart apple007 ASP.NET 1.0 and 1.1 Basics 0 July 25th, 2006 01:44 AM
ASP.NET Applications and Session Issue ricardoghunter Classic ASP Basics 0 September 13th, 2004 04:40 PM



All times are GMT -4. The time now is 07:30 AM.


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