Solved

I am trying to get the username from the login screen to write it to the database

Posted on 2010-09-04
8
369 Views
Last Modified: 2013-12-17
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
<%@ 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>

Open in new window

this is the code behind
using 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";
                    }
                }
        }
 
}

Open in new window

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
}

Open in new window


0
Comment
Question by:r3nder
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:systan
ID: 33605473
string NtAccountName;
NtAccountName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
MessageBox.Show(NtAccountName.ToString());
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33605518
since you haven't set any authentication on Default2 page you will not get the name here

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()

so changes are here

default2.cs

Response.Redirect("Default.aspx?txtBxUser.text");
 
to

Response.Redirect("Default.aspx?u=txtBxUser.text");


default.cs

string NtAccountName = Context.Request.QueryString["u"].ToString();
0
 
LVL 6

Author Comment

by:r3nder
ID: 33605522
Sorry comes back as NT AUTHORITY\NETWORK SERVICE
I tried something close to it
         WindowsIdentity currIdentity = WindowsIdentity.GetCurrent();
        string NtAccountName = currIdentity.Name.Substring(currIdentity.Name.IndexOf("\\") + 1);

This gave me Network service
I need the value of txtBxUser from the login form
0
 
LVL 6

Author Comment

by:r3nder
ID: 33605533
puru1981
Closer.........comes back as txtBxUser.text
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 9

Expert Comment

by:puru1981
ID: 33605541
sorry it should be

Response.Redirect("Default.aspx?u=" + txtBxUser.text);
0
 
LVL 6

Author Comment

by:r3nder
ID: 33605555

The error I get now is
System.Web.UI.WebControls.TextBox' does not contain a definition for 'text' and no extension method 'text' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found (are you missing a using directive or an assembly reference?)
0
 
LVL 9

Accepted Solution

by:
puru1981 earned 500 total points
ID: 33605559
txtBxUser.text -> txtBxUser.Text
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 33605577
Thank you sir
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SlingPlayer alternatives 1 35
I need help embedding Base64 Images using VB.Net - When image is a .jpg 2 42
Class object 2 27
Message not shown 5 33
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now