| | |
C# Login to my asp.net page
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 7
Reputation:
Solved Threads: 0
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
And then I have the authentication in C#:
And then on my upload page I have this:
Now I am trying to login using C#, I first found the input names of the login form using the sourcecode in Firefox:
And then I have this in my C# login application:
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:
HttpStatusCode.OK.
I should get a HttpStatusCode.Found if i'm correct?
This is how the login is done
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?
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
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="TourPortal_WebUpload.login" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Login ID="Login1" runat="server" DestinationPageUrl="login.aspx" Height="184px" onauthenticate="Login1_Authenticate" Width="264px"> </asp:Login> </div> </form> </body> </html>
And then I have the authentication in C#:
C# Syntax (Toggle Plain Text)
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { cTPDatabaseEngine.Initialize(); if (cTPDatabaseEngine.Login(Login1.UserName, Login1.Password)) { e.Authenticated = true; } else { e.Authenticated = false; } }
And then on my upload page I have this:
C# Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { if (!User.Identity.IsAuthenticated) { Response.Redirect("login.aspx"); }
Now I am trying to login using C#, I first found the input names of the login form using the sourcecode in Firefox:
C# Syntax (Toggle Plain Text)
<input name="Login1$UserName" type="text" id="Login1_UserName" /> <input name="Login1$Password" type="password" id="Login1_Password" />
And then I have this in my C# login application:
C# Syntax (Toggle Plain Text)
http.AddValue("Login1$UserName", username); 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:
C# Syntax (Toggle Plain Text)
if (rsp.StatusCode == HttpStatusCode.OK) { if (http.ResponseText.Contains("Username or password incorrect")) Console.WriteLine("Your login details were wrong."); //return; }
HttpStatusCode.OK.
I should get a HttpStatusCode.Found if i'm correct?
This is how the login is done
C# Syntax (Toggle Plain Text)
req.ContentLength = data.Length; st = req.GetRequestStream(); string s = Encoding.ASCII.GetString(data); string test = s; 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.
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- SQL SERVER 2000 Login failure in ASP.NET (ASP.NET)
- Help with ADMIN side of login ASP.NET (ASP.NET)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: Selecting multiple nodes in a tree view list
- Next Thread: post information between client application and web
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development draganddrop drawing encryption enum event excel file filename finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile gis globalization gtk httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser windows winforms wpf xml





