Tuesday, July 31, 2012

Check if the page is in iframe

There is a common requirement while developing iframe based web application i.e. redirect if the page is not in iframe or redirect main page to login page or any default page if the page is not opened with in iframe.
In such case; if some one tries to open page using URL; we need to check if the page is in iframe or not, if it is not in iframe we have to perform desired action. 
We can use following javascript to perform this checking and if the page is not in iframe redirect it to default page.

Submit this story to DotNetKicks

Read more...

Form Authentication Is Not Working

Form Authentication Is Not Working in IE 8. I am working on one web based project where I started with user management and struggled to make Form Authentication work... :( without testing it on other browsers. I had following settings in web.config...

      
    

After struggling for the day on "Form Authentication Is Not Working" and to Make it work... I tested it in Firefox and Google Crome and it did work very well :(, without any error. What I realized is, there is some Issue with IE 8 and Cookies we are using for Form authentication, so I made following change in Web.Config Setting.

      
    

Which in turn changed URL for IE 8 by adding some encoded information as a part of URL (going cookie-less), and in other browsers it allowed cookies and URL was without any Encoding added i.e. it was using Cookies. I hope this piece of Information will be Useful.
Submit this story to DotNetKicks

Read more...

Getting session state in httphandlers - ashx files

To do session state handling in Generic handlers or ashx files, there are two possibilities Readonly session state: we need to implement IReadOnlySessionsState interface, usefollowing demo code.
using System;
using System;
using System.Web;
using System.Web.SessionState;

public class Handler : IHttpHandler, IReadOnlySessionState
{

    public void ProcessRequest(HttpContext context)
    {
    if (HttpContext.Current.Session["SessionsName"] != null)
     {
      context.Response.Write(HttpContext.Current.Session["SessionsName"]);
     }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}
Read and Write Access to state: we need to implement IRequiresSessionState interface, usefollowing demo code.
using System;
using System.Web;
using System.Web.SessionState;

public class Handler : IHttpHandler, IRequiresSessionState
{

 public void ProcessRequest(HttpContext context)
  {
   if (HttpContext.Current.Session["SessionsName"] != null)
    {
      HttpContext.Current.Session["SessionsName"] = "Demo Session";
     }
   }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}
Submit this story to DotNetKicks

Read more...