Note that there are some explanatory texts on larger screens.

plurals
  1. POGet user ID and parse into session variable C#
    primarykey
    data
    text
    <p>I am working on an asp.net project in which I am trying to return the user ID of the current logged in use. I have written the user login in C# as I *<em>cannot</em> use the asp built in control due to other constraints. I want to get the user ID from a remote SQL database and then use it as a variable for another function. This is so I can assign the userID to the questionnaire that is being created in the function below. I have tried using the <code>membership.getUser</code> but with no luck.</p> <p>EDIT: When I run the project I get the error <strong>"System.NullReferenceException: Object reference not set to an instance of an object."</strong> which is pointing at <code>string UserID = membershipUser.ProviderUserKey.ToString()</code></p> <p><strong>new_questionnaire.aspx.cs</strong> (shortened)</p> <pre><code>using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Web.Security; using Questionnaire; public partial class new_questionnaire : System.Web.UI.Page { OsqarSQL sendData; protected void NewQnrButton_Click(object sender, EventArgs e) { // Check if the input fields are empty. if (QuestionnaireName.Text == "" || CustomerID.Text == "" || NumberOfQuest.Text == "") { lblError.Text = "Input fields cannot be blank"; } // Parse input values to OscarSQL. else { MembershipUser membershipUser = Membership.GetUser(); string userID = membershipUser.ProviderUserKey.ToString(); int testRet = sendData.InsertQuestionnaire(QuestionnaireName.Text, Int32.Parse(userID), Int32.Parse(NumberOfQuest.Text)); Session["QuestionnaireID"] = testRet; Session["QuestionnaireName"] = QuestionnaireName.Text; Response.Redirect("~/buildq/add_questions.aspx"); } } // End NewQNRButton_Click } // End new_questionnaire </code></pre> <p>Any help would be much appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload