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. Logout on click

Logout on click

Scheduled Pinned Locked Moved ASP.NET
comworkspace
2 Posts 2 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.
  • D Offline
    D Offline
    Dot Net Dev
    wrote on last edited by
    #1

    Following is my code for login: void Page_Load(object sender, EventArgs e) { string appURL = "http://www.mysite.com/Login.aspx"; string strPostData = String.Format("login={0}&password={1}", "myloginname", "mypassword"); // Setup the http request. HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as HttpWebRequest; wrWebRequest.Method = "POST"; wrWebRequest.ContentLength = strPostData.Length; wrWebRequest.ContentType = "application/x-www-form-urlencoded"; wrWebRequest.CookieContainer = new CookieContainer(); // Post to the login form. StreamWriter swRequestWriter = new StreamWriter(wrWebRequest.GetRequestStream()); swRequestWriter.Write(strPostData); swRequestWriter.Close(); // Get the response. HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse(); // Have some cookies. CookieCollection ccCookies = hwrWebResponse.Cookies; // Read the response StreamReader srResponseReader = new StreamReader(hwrWebResponse.GetResponseStream()); string strResponseData = srResponseReader.ReadToEnd(); srResponseReader.Close(); // Display the response. Response.Write(strResponseData); } It logs me in successfully but when I click on any link, it logs out. Please let me know what's going wrong.

    V 1 Reply Last reply
    0
    • D Dot Net Dev

      Following is my code for login: void Page_Load(object sender, EventArgs e) { string appURL = "http://www.mysite.com/Login.aspx"; string strPostData = String.Format("login={0}&password={1}", "myloginname", "mypassword"); // Setup the http request. HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as HttpWebRequest; wrWebRequest.Method = "POST"; wrWebRequest.ContentLength = strPostData.Length; wrWebRequest.ContentType = "application/x-www-form-urlencoded"; wrWebRequest.CookieContainer = new CookieContainer(); // Post to the login form. StreamWriter swRequestWriter = new StreamWriter(wrWebRequest.GetRequestStream()); swRequestWriter.Write(strPostData); swRequestWriter.Close(); // Get the response. HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse(); // Have some cookies. CookieCollection ccCookies = hwrWebResponse.Cookies; // Read the response StreamReader srResponseReader = new StreamReader(hwrWebResponse.GetResponseStream()); string strResponseData = srResponseReader.ReadToEnd(); srResponseReader.Close(); // Display the response. Response.Write(strResponseData); } It logs me in successfully but when I click on any link, it logs out. Please let me know what's going wrong.

      V Offline
      V Offline
      Viral Upadhyay
      wrote on last edited by
      #2

      From Your code it looks like you are login from other side, What you need to do is when you login successfully you need to set session values, And when you go to other page check this value so you will not log out. hint is when you sent login successfully response from other site, send some values like 'userid', and set this id session value.

      Viral My Site
      Save Our Tigers

      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