You must Sign In to post a response.
  • Category: ASP.NET

    System.nullreferenceexception while redirecting to page

    I am checking session in each content page and even in master page also.It is working fine with all pages other than one page(Test.aspx).In Test.aspx page it gives error when session is null.How can I handle this?

    If(Session["LoginId"] == null)
    {
    Response.redirect("SessionClear.aspx",false)
    }
    In SessionClear.aspx page ,I am clearing session and redirecting to Login page.
  • #735184
    Hi,

    Can you post the complete code used in your test.aspx. I doubt this error is throwing because of this code. Did you try to debug the code? If you are getting this exception from this line then please post complete stack trace to analyse.


    Regards,
    Asheej T K

  • #735192
    Thanks Asheej for ur reply.Test.aspx is content page.In this page's load method I am checking
    try
    {
    session.If(Session["LoginId"] == null)
    {
    Response.redirect("SessionClear.aspx",false)
    }
    }
    catch(Exception ex)
    {
    label1.Text = ex.Tostring()
    }.
    When session is null,it enter into this block.After that it move to master page.In master page also I am checking session state.
    page_load()
    {
    try
    {
    session.If(Session["LoginId"] == null)
    {
    Response.redirect("SessionClear.aspx",false)
    }
    }
    catch(Exception ex)
    {
    label1.Text = ex.Tostring();
    }
    }// after this bracket error is thrown.It is not
    catched.Suppose to redirect to sessionclear.aspx page.But it is not happening.

  • #735196
    Hi pinky,

    Better to put a breakpoint and check line by line to achieve your goal and better to use Try and Catch blocks to raise error message.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments