Problem with HttpResponse

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dada1
    New Member
    • Jul 2008
    • 15

    #1

    Problem with HttpResponse

    error is The name 'Response' does not exist in the current context
    Line 57

    Code:
    using MySql.Data.MySqlClient;
    using System.Web;
    
    
    
    
    namespace login
    {
        
        public partial class Form1 : Form
        {
            MySqlConnection konekcija;
            string baza = "host=localhost;database=test;user=root;password=";
            MySqlCommand comm;
            MySqlDataReader reader;
            HttpCookie cookie;
    
            
             
    
            public Form1()
            {
                InitializeComponent();
            }
            
            
    
            private void Form1_Load(object sender, EventArgs e)
            {
                konekcija = new MySqlConnection(baza);
                comm = konekcija.CreateCommand();
                konekcija.Open();
    
                
            }
    
    
    
            private void button1_Click(object sender, EventArgs e)
            {
               
                string user = textBox2.Text.ToString();
                string pass = textBox1.Text.ToString();
                trylogin( user,  pass);
    
            }
    
            public void trylogin(string user, string pass)
            {
    
                if (checkBox1.Checked)
                {
                    cookie = new HttpCookie("remember_me");
                    cookie["Username"] = textBox2.Text;
                    cookie["Expire"] = "365 Days";
                    cookie.Expires = DateTime.Now.AddDays(365);
                    Response.Cookies.Add(cookie);
                    
    
                }
                
                comm.CommandText = "SELECT * FROM korisnici WHERE user='"+user+"' AND pass='"+pass+"'";
                
                reader = comm.ExecuteReader();
                if (reader.Read() == true)
                {
                    
                    reader.Dispose();
                }
                else 
                {
                    reader.Dispose();
                }
                
            }
    
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                konekcija.Close();
            }
        }
    }
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Response is something that doesn't exist, you'll probably want to make sure you create an HttpWebRequest. You can then call GetResponse() on that object and that should give you your HttpResponse.

    I only have minor experience with this stuff, but I once got a web page with login working by using an HttpWebRequest to log into the page with my credentials as parameters. I then created a new request for the web page I actually wanted (which required the login) and set the cookie container of that request to the cookie container of the first.

    Something like (not real code...)

    Code:
    HttpWebRequest loginRequest = ...
    loginRequest.CookieContainer = new CookieContainer();
    /* copy the parameters into the request */
    loginRequest.GetResponse();
    
    HttpWebRequest actualRequest = ...
    actualRequest.CookieContainer = loginRequest.CookieContainer;
    /* carry on with actual request */
    Hopefully that helps in some way... you might have to fudge around with it a bit. What I was trying to do here was access data from the Battlefield 3 Battlelog page before they made it publicly available. I had to login first, then request the data I wanted. They subsequently made everything public so I didn't have to do that anymore. I commented out all the code so I could keep it around, but I haven't used it in a long time.

    Good luck!

    Comment

    Working...