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. General Programming
  3. C#
  4. How to use session ??

How to use session ??

Scheduled Pinned Locked Moved C#
databasecsharpasp-nethelptutorial
1 Posts 1 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.
  • L Offline
    L Offline
    lsh486love
    wrote on last edited by
    #1

    I'm making a login page with ASP.NET with C#. and I know that it needs to use Session for saving information of loggined user. so I used Session like this on "login.aspx.cs" with Login View Control. [login.aspx.cs] // Database query. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Join"].ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * From User WHERE id = @ID", con); cmd.Parameters.AddWithValue("@ID", ((TextBox)LoginView1.FindControl("TextBox1")).Text); string name = rd["name"].ToString(); string pw = rd["password"].ToString(); string pw1 = ((TextBox)LoginView1.FindControl("TextBox2")).Text; string id = rd["id"].ToString(); // Save to Session variables. There are a lot of components about Session. Keys, Item, Add, //and so on.. Session["memberid"] = id; Session["membername"] = name; if ((string.Equals(pw, pw1)) == true) { FormsAuthentication.RedirectFromLoginPage(name, false); } .... And I made codes like this whether lggined user is same with Writer on board or not. [Board.aspx] public static bool IsWriter(string pdsId, string Writer) { string sql = "Select id From t_Pds Where boardId = @boardId And writer = @writer"; SqlCommand cmd = new SqlCommand(sql, DbConn.GetConn()); cmd.Parameters.AddWithValue("@boardId", pdsId); cmd.Parameters.AddWithValue("@writer", Writer); cmd.Connection.Open(); string result = (string)cmd.ExecuteScalar(); // result = ID of writer value. cmd.Connection.Close(); // I can't use Session. When I use "Session", there are no components of Session. // There are only two values of Session. ( SessionPageStatePersister , SessionParameter) if (Session["memberid"] == result) //ERROR. { return true; } else return false; } }

    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