locked
HTML Extension mapped to aspnet_isapi.dll showing weird results RRS feed

  • Question

  • User-865566677 posted

    Hello,

    In my ASP.NET application I am tracking user behavior ( tracking pages visited by user ) . For doing this I created a HTTPModule and attached with the application. Everything worked smoothly. But my website contains numbr of HTML pages, so this HTTPModule was not tracking this HTML pages. For doing this, I mapped html and htm extensions to aspnet_isapi.dll in IIS. Now it started to track HTML pages also.

     For tracking each user behaviors, I was storing his id in one session. But in HTML pages this session failed to work. It throws "session state is not available in this context exception". I have added HttpHandlers for html and htm pages and mapped to System.Web.UI.PageHandlerFactory. Still I am getting the same error. Any body please help me to solve this issue ?

    If the page is mapped to ASPX engine, then it will be served by that engine rite, So session also should be available. But why this is happening in my scenario ? When I am going wrong ? Please guide.
     

    Wednesday, August 22, 2007 9:11 AM

All replies

  • User1622957740 posted

    Where are you calling the Session code? Session won't be available until the Session module has fired and retrieved session data which is in AcquireRequestState which fires just before the handler executes. Anytime before that event - you have no Session state.

    That doesn't explain why this only happens with HTML files though but I bet there's something in your codepath that's different?

     +++ Rick ---

    Wednesday, August 22, 2007 2:29 PM
  • User-865566677 posted

    Hello,

    Thank you very much Rick for your excellent reply.

    Where are you calling the Session code?
     

    I am calling the session code in  PrerequestHandelerExecute event. I think session state will be available here. Below is my code for that event

     

    private void PreRequestHandlerExecute(Object source,EventArgs e)
    {
    	HttpApplication CurrentApp = (HttpApplication)source;	//Getting HTTPApplication object
    	//Starting tracking
    	CustomerPageTracker PageTracker = new CustomerPageTracker();
    	PageTracker.CurrentApplication = CurrentApp;
    	PageTracker.StartTracking();
    }

      

    Below is my StartTracking() method

     

    public override void StartTracking()
    {
    	System.Web.HttpRequest _Request = this.CurrentApplication.Request;
    	if ( this.IsTrackingEnabled )
    	{
    		string CurrentSession = string.Empty;
    		if ( !this.SessionExist() )
    		{
    			//Session not exist. So inserting into master table and detail
    			using ( CDatabase ObjDb = new CDatabase(this.DBConnectionString) )
    			{
    				string Referer = string.Empty;	//Referer for the requested page
    				if ( _Request.UrlReferrer != null )
    					Referer = _Request.UrlReferrer.AbsoluteUri;
    				else
    					Referer = "No referer";
    				//inserting into master table. this will return current identity value
    				CurrentSession = ObjDb.InsertVisitorMain(_Request.ServerVariables["Remote_Host"],
    						Referer,_Request.Browser.Type,_Request.Browser.Platform);
    				ObjDb.InsertVisitorDetails(CurrentSession,_Request.Url.AbsoluteUri);
    				SetSession(CurrentSession);	//Setting session
    			}
    		}
    		else
    		{
    			using ( CDatabase ObjDb = new CDatabase(this.DBConnectionString) )
    			{
    				ObjDb.InsertVisitorDetails(this.VisitorId,_Request.Url.AbsoluteUri);
    			}
    		}
    
    		//Checking user logged in the website. If yes updating customer login id field
    		if ( IsWebsiteSessionExist() )
    		{
    			using ( CDatabase ObjDb = new CDatabase(this.DBConnectionString) )
    			{
    				ObjDb.UpdateCustomerLoginId(this.WebsiteLoginId,this.VisitorId);
    			}
    		}
    	}
    			
    }

     

    I am getting error in SetSession Method which is as follows

     

    private void SetSession(string VisitorId)
    {
    	this.CurrentApplication.Session["VisitorId"] = VisitorId;
    	this.VisitorId = VisitorId;
    }

      

    This whole things are working fine for all ASPX pages. But it is throwing session state error for HTML pages. If HTML pages are mapped to ASP.NET engine, then HTML pages also served like ASPX pages only. is it So ?  But still this error comes.   

    Thursday, August 23, 2007 12:57 AM