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
<%@ 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#:
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:
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:
<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:
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:
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
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?