Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Pass LoginName in InsertParameters

Posted on 2006-04-05
6
Medium Priority
?
742 Views
Last Modified: 2012-06-21
Whenever a record is inserted into the database, I would like to store the username of the user that inserted the record by passing their login name as a parameter in the SqlDataSource.  How would I go about doing that?  I am using ASP .Net Membership and Roles.

Thanks for your help!
0
Comment
Question by:qryz
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Torrwin earned 1000 total points
ID: 16386380
You could try using Context.User.Identity.Name, I haven't tried that with membership and roles myself though.
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 16398513
you can get the authenticated user name from the server variables -  eg once they are authenticated then the user name is stored in the a spefic key AUTH_USER in a server vairable. Below shows how to get some info from these keys in c#...

make sure these are added
using System.Collections;
using System.Collections.Specialized;

            //code below
            DateTime dt = new DateTime();
            dt = DateTime.Now;
            string date = dt.ToString("s", System.Globalization.DateTimeFormatInfo.InvariantInfo);
            date = date.Replace('T', ' '); //datetime now yyyymmdd HHmmss

            //get collection of server variables
            NameValueCollection coll;
            coll = obj.ServerVariables;

            String[] arr1 = coll.AllKeys;

            // set sql string
            string insert = "insert into users_log(username,pswd,AUTH_TYPE,AUTH_USER,REMOTE_USER,REMOTE_ADDR,REMOTE_HOST,SCRIPT_NAME,URL,HTTP_USER_AGENT,datetime) " +
                            "values('" + username + "','" + pswd + "','" +
                            coll.GetValues("AUTH_TYPE").GetValue(0) + "','" +
                            coll.GetValues("AUTH_USER").GetValue(0) + "','" +
                            coll.GetValues("REMOTE_USER").GetValue(0) + "','" +
                            coll.GetValues("REMOTE_ADDR").GetValue(0) + "','" +
                            coll.GetValues("REMOTE_HOST").GetValue(0) + "','" +
                            coll.GetValues("SCRIPT_NAME").GetValue(0) + "','" +
                            coll.GetValues("URL").GetValue(0) + "','" +
                            coll.GetValues("HTTP_USER_AGENT").GetValue(0) + "','" +
                            date + "')";
            //check sql
            ...
            //insert sql into db
            ...
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 16593186
personaly i think that there is more effort in my solution and more flexibility if you need to track remote ip's
0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16593478
That may be the case, but the original question was

"passing their login name as a parameter in the SqlDataSource"

Since only the login name was requested, Torrwin's simple posting would have given the correct requirement.
Our rule of thumb is first in gets the points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 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