User-1559458579 posted
Visual Studio 2019
ASP.Net 4.7
Language C#
Using Code Behind
Identity
Insert Method - SQLDataSource using - protected void Page_Load(object sender, System.EventArgs e)
{
InsertCompany.Insert();
}
I have created a table and I will be inserting records in a database through the
asp.net web application. My issue is I want to insert the value of the logged user with the record that is being created. If a user enters Company information I want the UserId field to be populated
with the logged in user for the record being inserted. I have gone as far as I can go with this code. My plan is to assign the logged in user value to a field on the submit form. Below is the code I have so far but I'm not able to get it any further. If you
can help please supply the code as telling me what would be best to do won't help me much. I would need the actual code. Also, I'm fairly certain the code I provided is not correct. I wanted to attempt to get it before I reached out. I have already successfully
created inserting functionality. I simply need to add the additional field of UserID as part of the Insert.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
namespace WebApplication13
{
public partial class Backoffice_main : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
string UserId;
_ = HttpContext.Current.User.Identity.Name;
if (!User.Identity.IsAuthenticated)
return;
UserId =
User.Identity.ToString
}
}
Also trying this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Claims;
using System.Security.Authentication;
using System.Web.Security;
using Microsoft.AspNet.Web;
namespace echov_4
{
public partial class Weblogic5 : System.Web.UI.Page
{
//protected void Page_Load(object sender, System.EventArgs e)
//{
// InsertCompany.Insert();
//}
protected void Page_Load(object sender, System.EventArgs e)
{
if (User.Identity.IsAuthenticated)
Label1.Text = User.Identity.Name;
else
Label1.Text = "No user identity available.";
}
}
}