C# Login to my asp.net page

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 7
Reputation: Kekke is an unknown quantity at this point 
Solved Threads: 0
Kekke Kekke is offline Offline
Newbie Poster

C# Login to my asp.net page

 
0
  #1
Apr 24th, 2009
Hello.

I am trying to make a C# application login on my ASP.NET page.

I am using a login control to check the login.

login.aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="TourPortal_WebUpload.login" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7. <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div>
  12.  
  13. <asp:Login ID="Login1" runat="server" DestinationPageUrl="login.aspx"
  14. Height="184px" onauthenticate="Login1_Authenticate" Width="264px">
  15. </asp:Login>
  16.  
  17. </div>
  18. </form>
  19. </body>
  20. </html>

And then I have the authentication in C#:

  1. protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
  2. {
  3. cTPDatabaseEngine.Initialize();
  4. if (cTPDatabaseEngine.Login(Login1.UserName, Login1.Password))
  5. {
  6. e.Authenticated = true;
  7. }
  8. else
  9. {
  10. e.Authenticated = false;
  11. }
  12. }

And then on my upload page I have this:
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (!User.Identity.IsAuthenticated)
  4. {
  5. Response.Redirect("login.aspx");
  6. }

Now I am trying to login using C#, I first found the input names of the login form using the sourcecode in Firefox:
  1. <input name="Login1$UserName" type="text" id="Login1_UserName" />
  2. <input name="Login1$Password" type="password" id="Login1_Password" />

And then I have this in my C# login application:

  1. http.AddValue("Login1$UserName", username);
  2. http.AddValue("Login1$Password", password);

Where username & password is my username & password.

I can login when browsing the site with firefox but not in my Application.

The ResponseCode I get is this:
  1. if (rsp.StatusCode == HttpStatusCode.OK)
  2. {
  3. if (http.ResponseText.Contains("Username or password incorrect"))
  4. Console.WriteLine("Your login details were wrong.");
  5. //return;
  6. }

HttpStatusCode.OK.

I should get a HttpStatusCode.Found if i'm correct?

This is how the login is done
  1. req.ContentLength = data.Length;
  2. st = req.GetRequestStream();
  3. string s = Encoding.ASCII.GetString(data);
  4. string test = s;
  5. st.Write(data, 0, data.Length);



Why do I get the HttpStatusCode.OK?
Is there something weird when using asp.nets login control to login using an application?

Problem is it won't even let me login, the code works when uploading a file without authentication, I have cookies set if I get any.

Anyone have any idea?
Last edited by Kekke; Apr 24th, 2009 at 8:55 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC