Click here to Skip to main content
Licence CPOL
First Posted 24 Feb 2009
Views 8,562
Bookmarked 5 times

Frames, Sessions, and P3P

By | 24 Feb 2009 | Article
Create a module to deal with Sessions in Frames.

Introduction

A while ago, I encountered a problem resulting from the inability of session variables to be available cross-domain, specifically when using Frames.

Background

This problem occurs when you have a web page which contains a frame(s) whose source location is cross domain,or resides on a separate server.

Using the code

After some research, I found that a solution to this problem would be to add/modify the necessary HTTP headers programmatically.

Adding an HTTP header would need to occur before any page HTML is added. The best way to do this would be by an external module where we can add our header at the very beginning of the application request. Since this problem was apparent on a number of our applications, this would be ideal as we could also re-use this module.

Let's create a module that would add the required header for us. First, create a new Class Library project. Let's call it ApplicationModule. Now, add a new class to our ApplicationModule project called Application.cs. Implement the interface IHttpModule. We now create a private method OnStartOfApplication that does the addition of the required header to solve our problem. This method will be called on application initialization via the Application Init method.

public class ModuleRuss : IHttpModule
{
#region IHttpModule Members

     public void Dispose()
     {
     }

     public void Init(HttpApplication context)
     {
          context.BeginRequest += (new EventHandler(this.OnStartOfApplication ));
     }

#endregion

     private void OnStartOfApplication (Object source, EventArgs e)
     {
          HttpContext.Current.Response.AddHeader("p3p", 
            "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
     }
}

So, how do we get this to work in our Web Application?

First, we need to add a reference to our ApplicationModule.dll in our Web Project. We then need to reference our newly added ApplicationModule in our Web.Config file within the <httpModules> section:

<add name="externalModule" type="ApplicationModule.Application, ApplicationModule"/>

Points of interest

So now, using Fiddler or IE Watch, you can view your Response Headers and see that you have a new entry for P3P. This helped solve my problem; hope it helps solve yours.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

butchzn



South Africa South Africa

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAwesome, worked flawless Pinmembervbextra6:54 5 Aug '10  
GeneralFantastic 5/5 PinmemberArash Javadi0:03 8 Jun '09  
GeneralMy vote of 2 PinmemberAdam L. Stevenson12:06 24 Feb '09  
GeneralEasier Solutions PinmemberLeeland Clay10:35 24 Feb '09  
GeneralRe: Easier Solutions PinmemberMember 36548916:48 19 Mar '09  
QuestionWhy? Pinmemberzlezj9:39 24 Feb '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 24 Feb 2009
Article Copyright 2009 by butchzn
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid