Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. session problem

session problem

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Soumini Ramakrishnan
    wrote on last edited by
    #1

    protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["mysession"].ToString() != null) { Label1.Text = "Welcome " ; } else { Response.Redirect("Login.aspx"); } } } I have the above code in one aspx page. Before logging in if someone opens this page, it should open Login page. But instead of showing theLogin page, it shows Server Error. Any one have an idea.

    S N K S 4 Replies Last reply
    0
    • S Soumini Ramakrishnan

      protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["mysession"].ToString() != null) { Label1.Text = "Welcome " ; } else { Response.Redirect("Login.aspx"); } } } I have the above code in one aspx page. Before logging in if someone opens this page, it should open Login page. But instead of showing theLogin page, it shows Server Error. Any one have an idea.

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      What error are you getting in the page ? Could you clarify that

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      1 Reply Last reply
      0
      • S Soumini Ramakrishnan

        protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["mysession"].ToString() != null) { Label1.Text = "Welcome " ; } else { Response.Redirect("Login.aspx"); } } } I have the above code in one aspx page. Before logging in if someone opens this page, it should open Login page. But instead of showing theLogin page, it shows Server Error. Any one have an idea.

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Soumini Ramakrishnan wrote:

        if (Session["mysession"].ToString() != null)

        This is wrong. It should be

        if (Session["mysession"] != null)
        {
        Label1.Text = "Welcome " ;
        }
        else
        {
        Response.Redirect("Login.aspx");
        }

        When session is null, you can't invoke it's ToString() method.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        1 Reply Last reply
        0
        • S Soumini Ramakrishnan

          protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["mysession"].ToString() != null) { Label1.Text = "Welcome " ; } else { Response.Redirect("Login.aspx"); } } } I have the above code in one aspx page. Before logging in if someone opens this page, it should open Login page. But instead of showing theLogin page, it shows Server Error. Any one have an idea.

          K Offline
          K Offline
          Krishnraj
          wrote on last edited by
          #4

          Hi, I had made some changes in yr code, just see below. Try this code, i hope u can not get an error...

          if (!IsPostBack)
          {
          if (Session["mysession"] != null)
          {
          Label1.Text = "Welcome ";
          }
          else
          {
          Label1.Text = "test";
          }
          }

          i hope it will help u..

          Rana Krishnraj

          modified on Wednesday, April 2, 2008 9:30 AM

          1 Reply Last reply
          0
          • S Soumini Ramakrishnan

            protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["mysession"].ToString() != null) { Label1.Text = "Welcome " ; } else { Response.Redirect("Login.aspx"); } } } I have the above code in one aspx page. Before logging in if someone opens this page, it should open Login page. But instead of showing theLogin page, it shows Server Error. Any one have an idea.

            S Offline
            S Offline
            Soumini Ramakrishnan
            wrote on last edited by
            #5

            Thank you all. The given hints helped me and I rectified my problem.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups