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