r3nder
asked on
I am trying to get the username from the login screen to write it to the database
I am trying to get the username on login form and assign it to a variable and write it to the database - Below is what I have so far, but I am stuck
this is the login page..........Please help
this is the login page..........Please help
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Default2" %>
<!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>Login</title>
</head>
<body>
<form id="form1" runat="server">
<div align = "Left">
<table style="width: 100%;">
<tr>
<td><asp:Label ID="Label3" runat="server" Text="Domain: "></asp:Label></td>
<td><asp:TextBox ID="txtBxDomain" runat="server" text="Domain" ReadOnly="true"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="Label1" runat="server" Text="Username:"></asp:Label></td>
<td><asp:TextBox ID="txtBxUser" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="Label2" runat="server" Text="Password:"></asp:Label></td>
<td><asp:TextBox textmode="password" ID="txtBxPass" runat="server"></asp:TextBox></td>
</tr>
</table>
<asp:Button ID="btnLogon" runat="server" Text="Verify" onclick="Submit_ServerClick"/>
<br /><asp:Label ID="lblError" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
this is the code behindusing System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Security.Principal;
using System.DirectoryServices;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Submit_ServerClick(object sender, EventArgs e)
{
//Response.Redirect("Default.aspx");
//program p = new program();
if (!String.IsNullOrEmpty(txtBxDomain.Text.Trim()) && !String.IsNullOrEmpty(txtBxUser.Text.Trim()))
{
if (program.LogonHelper.VerifyADLogon(txtBxDomain.Text, txtBxUser.Text, txtBxPass.Text))
{
Response.Redirect("Default.aspx?txtBxUser.text");
}
else
{
lblError.Text="Please try again";
}
}
}
}
This is where I am trying to assign it protected void Page_Load(object sender, EventArgs e)
{
//
string NtAccountName = Default2.txtBxUser;
//WindowsIdentity currIdentity = WindowsIdentity.GetCurrent();
//string NtAccountName = currIdentity.Name.Substring(currIdentity.Name.IndexOf("\\") + 1);
Response.Write(NtAccountName);
if (NtAccountName == "Render" || NtAccountName == "r3nder")
{
//my code
}
since you haven't set any authentication on Default2 page you will not get the name here
System.Security.Principal. WindowsIde ntity.GetC urrent().N ame.ToStri ng()
so changes are here
default2.cs
Response.Redirect("Default .aspx?txtB xUser.text ");
to
Response.Redirect("Default .aspx?u=tx tBxUser.te xt");
default.cs
string NtAccountName = Context.Request.QueryStrin g["u"].ToS tring();
System.Security.Principal.
so changes are here
default2.cs
Response.Redirect("Default
to
Response.Redirect("Default
default.cs
string NtAccountName = Context.Request.QueryStrin
ASKER
Sorry comes back as NT AUTHORITY\NETWORK SERVICE
I tried something close to it
WindowsIdentity currIdentity = WindowsIdentity.GetCurrent ();
string NtAccountName = currIdentity.Name.Substrin g(currIden tity.Name. IndexOf("\ \") + 1);
This gave me Network service
I need the value of txtBxUser from the login form
I tried something close to it
WindowsIdentity currIdentity = WindowsIdentity.GetCurrent
string NtAccountName = currIdentity.Name.Substrin
This gave me Network service
I need the value of txtBxUser from the login form
ASKER
puru1981
Closer.........comes back as txtBxUser.text
Closer.........comes back as txtBxUser.text
sorry it should be
Response.Redirect("Default .aspx?u=" + txtBxUser.text);
Response.Redirect("Default
ASKER
The error I get now is
System.Web.UI.WebControls.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you sir
NtAccountName = System.Security.Principal.
MessageBox.Show(NtAccountN