store logon username in database

sadesh kumar asked on May 29, 2014 09:01

I have added an user control page to store the data to the external database but the logon user name is not stored in the sql database column.I have used the following code: SqlCommand cm = new SqlCommand(" INSERT INTO jobpost (postedby ) VALUES ('" +CMSWebParts_Membership_Logon_currentuser.CacheItems.ToString()+ "')", cn);

Correct Answer

Jakub Oravec answered on May 29, 2014 10:05

Hi Sadesh,

CacheItems property of CurrentUser webpart does not contain user name. Actually, it contains a key for partial cache. If you need user name of current user you can use following code:

CMS.Membership.MembershipContext.AuthenticatedUser.UserName // for Kentico 8
CMS.CMSHelper.CMSContext.CurrentUser.UserName // for Kentico 7
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.