0
Answer

Taking UserId from membership and storing in a table

Ask a question
Sheikh parvaz

Sheikh parvaz

11y
1.1k
1
namespace Supportticketsystem.Admins
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TicketConnectionString"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {
            con.Open();
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            Session["UserLoginName"] = User.Identity.Name;
            string ticketstatus = "Pending";
            string userid = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString();
            SqlCommand cmd = new SqlCommand("Insert into Ticket(Type,Department,Category,Title,Detail,CreatedBy,CreateDate,UserId,CurrentStatus,CurrentStatusDate,LastUpdatedDate,LastUpdatedBy,RoomNo,Availabilty) values('" + ddlType.Text + "','" + ddlDepartment.Text + "','" + ddlCategory.Text + "','" + txtSubject.Text + "','" + txtMessage.Text + "','" + txtName.Text + "','" + userid + "','" + ticketstatus + "','" + DateTime.Now + "','" + Session["UserLoginName"] + "','" + DateTime.Now + "','" + txtRoom+ "','" + ddlAvailability.Text + "')", con);
            cmd.ExecuteNonQuery();
            con.Close();
            Label4.Visible = true;
            Label4.Text = "Data inserted successfully";
        }

       

    }
}


The above code is running good but "string userid = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString();" line is showing error. It says "  string userid = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString();" 
kindly help me out.  

In above example I want to store information from textboxs, dropdownlists etc and also need UserId and UserName. Which I am trying from membership. Show the correct form of doing this pls. Also suggest if there is a better way.