Friday, April 11, 2008


How to keep session alive in iframe based application.

When i am developing application in Face Book i creating session in page where user first login.But when i check for this same session on another page after redirecting i get nothing it means session is empty and this is only for IE browser not for FIREFOX.i search this over net i find different solution from one of them i used but this also giving me error but from that i try my solution and it's work.

I like to share this with internet user from this some of them can get their solution.

If an ASP.NET page is embedded in a frame set or an iframe, one thing happen to cookies. By default, Internet Explorer rejects them because it treats them as non-trusted “third-party” unwanted objects.If you face this issue an authentication cookie within a “framed” page, your login will keep running in infinte.

Why these happen for i frame ?
Internet Explorer 6 introduced Platform for Privacy Preferences (P3P) Project. The P3P notes that if a FRAME SET references another site inside a FRAME , the child site is considered third party content. Internet Explorer, uses the default privacy setting as Medium Trust, so IE rejects cookies sent from third party sites.

Solution : There is two methods


1) Internet Explorer users can modify their privacy settings so that will prompted to accept third party content. Follow below steps how to modify the privacy settings:

  • Run Internet Explorer.
  • Click Tools, and then click Internet Options.
  • Click the Privacy tab, and then click Advanced.
  • Click to select the Override automatic cookie handling check box.
  • To allow ASP and ASP.NET session cookies to be set, click to select the Always allow session cookies check box.
  • To receive a prompt for any type of third party cookie, click Prompt in the Third-party Cookies list.

2) You can add a P3P compact policy header to your child pages,

You can declare that no malicious actions are done with the data of the user. If Internet Explorer detects a sufficent policy,
then Internet Explorer permits the cookie to be set.

Copy and paste the below code in your "Page_Prerender" event.

Dim strHeader As String = "CAO PSA OUR\"
HttpContext.Current.Response.AddHeader("p3p", "CP=\" &
strHeader & " ")
Page.ClientScript.RegisterForEventValidation(Me.UniqueID)

A simple compact policy that fulfills the needed criteria follows:

P3P: CP="CAO PSA OUR"

In above code say that your site provides you access to your own contact information (CAO), that any analyzed data is only "pseudo-analyzed",
which means that the data is connected to your online role and not to your physical identity (PSA), and that your data is not supplied to any outside
agencies for those agencies to use (OUR). This is sufficient to get Internet Explorer to allow the Session cookie, as well as other cookies.


If you have been having Session or other cookie problem when you are using frames on your pages, try this to fix it.


"SAVE PAPER - THINK BEFORE YOU PRINT!"


Thursday, April 10, 2008



How to Debug Java script in Vs2003 and Vs2005.



Every one of us is well aware of problems we face when debugging client side script code. i find new techniques and troubleshooting tips that help debug client side script code efficiently in Visual studio 2003-2005.

Client side script code means that it can be VB Script Java script. Client side script is embedded in .aspx pages, .html files or inside .js files. Client side script is loaded by client application like Internet Explorer running on your local machine.


There are two different ways in which can debug client side scripts in Visual Studio
2005. They are :

  • Visual Studio .Net IDE
  • Microsoft Script Editor

1) Configuring machine to enable client side script debugging.

Enable client side script debugging in Internet Explorer. Go to Tools -- > Internet
Options and on advanced tab make sure that the Disable script debugging is unchecked.
Below listing highlights above step.




We create an small ASP.NET small web application that greets the user.
Open Visual Studio 2003/2005 Environment and On the File menu create new web application with give name what you like.

Copy and paste below code in your script tag of head section.
function Greeting()

{

//debugger keyword invokes Script explorer
debugger;
var firstname;
var lastname;
var greeting;

firstname = document.all('txtName1').value;
lastname = document.all('txtName2').value;
greeting = "Hello" + " "+ firstname + " " + lastname + " " + "Have a great Day!";
alert(greeting);
return false;
}


Copy and paste below code and paste between your forms tags.
















FirstName:


LastName:





Press F5 to start debugging. IEXPLORE.EXE process is attached automatically to debugger. We are using
IE to load the scripts so IEXPLORE.EXE is attached.


Note :
You should always include keyword "debugger" as the first line of Java script code you wish to debug in Visual studio 2005.


This keyword automatically invokes Visual Studio client side debugger.
When you run above code, we get the below output Screen 2 Go back to Visual Studio .Net environment and click Debug -- >Other windows-->Script Explorer and set the breakpoints at the desired places. Again return back to IE. Give the values for the first name and last name and click greeting button. You can see control returning to Script Explorer as shown in below listing. Use F10 to step over each line of code. Similarly, use F11 to step into each line
of code. In script explorer, you can set new breakpoints and use Locals Window to inspect values of local variables in the script. Immediate Window evaluates the values of variables. See the Data tips by hovering over the variables.


When you use a "Debugger;" in Java script.

Debugger keyword will create a breakpoint. When this breakpoint gets hit, your MSE will launch and you will see a message that says "An unhand led exception 'Script Breakpoint' occurred" in script.



Choose yes and remaining steps are same as discussed as above .Control is transferred to Script Editor IDE.


Visual Studio 2003/2005 Integrated debugger is very powerful and rich in features. You can now debug client side script code with the same flexibility as you used to have with debugging server
side code.

Now say Good Bye to alert statement .Cheers :-)

"SAVE PAPER - THINK BEFORE YOU PRINT!"

About Me

Ahemdabad, Gujarat, India
I am software Programmer