Pass LoginName in InsertParameters

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!
qryzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TorrwinCommented:
You could try using Context.User.Identity.Name, I haven't tried that with membership and roles myself though.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deanvanrooyenCommented:
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
            ...
deanvanrooyenCommented:
personaly i think that there is more effort in my solution and more flexibility if you need to track remote ip's
GavinMannionCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.