views:

59

answers:

4

I check for a session variable in my asp.net page and redirect to my default page.

 if (Session["OrgId"] != null)
   {
       // some logic
   }
 else
   {
             Response.Redirect("../Default.aspx?Sid=1", false);
   }

and in my default.aspx page i ve done this,

Int64 id = GetId(Request.RawUrl.ToString());
  if (id == 1)
 {
    // I ll show "Session Expired"
 }

public Int64 GetId(string url)
{
    Int64 id = 0;
    if (url.Contains("="))
    {
        if (url.Length > url.Substring(url.LastIndexOf("=")).Length)
        {
            id = Convert.ToInt64(url.Substring(url.LastIndexOf("=") + 1));
        }
    }
    return id;
}

This works in googlechrome,firefox but not in IE. "Operation aborted" exception.

+3  A: 

try changing

 Response.Redirect("../Default.aspx?Sid=1", false);

to

 Response.Redirect("../Default.aspx?Sid=1"); 

or

Response.Redirect("../Default.aspx?Sid=1", true);
ajay_whiz
+1  A: 

HttpResponse.Redirect Method

Redirect(String, Boolean) Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.

That means that Response.Redirect("../Default.aspx?Sid=1", false); won't terminate the current response.

sshow
A: 

IE is much more sensitive than other browsers about changing the DOM after headers have been sent but before the page terminates.

Here is your problem:

Response.Redirect("../Default.aspx?Sid=1", false);

Try changing false to true.

Also, be very careful about the casing in your page names. "Default.aspx" and "default.aspx" are really not the same page even if Windows lets you get away with it.

Justin
A: 

Can you also not replace all of this:

Int64 id = GetId(Request.RawUrl.ToString());
  if (id == 1)
 {
    // I ll show "Session Expired"
 }

public Int64 GetId(string url)
{
    Int64 id = 0;
    if (url.Contains("="))
    {
        if (url.Length > url.Substring(url.LastIndexOf("=")).Length)
        {
            id = Convert.ToInt64(url.Substring(url.LastIndexOf("=") + 1));
        }
    }
    return id;
}

with

int64 id = int64.parse(Request["Sid"]);
Ashley