p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=554)
-   -   Storing Additional User Information (C#) Issue (http://p2p.wrox.com/showthread.php?t=89516)

phil5p March 9th, 2013 12:34 PM

Storing Additional User Information (C#) Issue
Hi Everyone,

I thought I might try the forum for some help. I used the book beginning asp.net to create my final year project website and thought I was somewhat hot stuff [:)]

However, I used the profile function as demonstrated in the book and found I needed some other way of recording a user profile. My issue's with profile were:

I had problems using the query wizard within my website
I could not edit and update the record
I wanted to assign records default values and drop down boxes, from research I couldn't

I wanted to use profile to allow a logged in user to update their profile, they should only see their profile after logged in.

I found the following tutorial online which seems to do everything I required, albeit somewhat simple. http://www.asp.net/web-forms/tutoria...information-cs

I have followed the tutorial as required and cannot seem to get it to work. Ok, so following the tutorial, the first error I get is:

Error 2 The name 'Membership' does not exist in the current context C:\Users\Philip\Desktop\WebSite5\LoggedProfile.asp x.cs 19 38 C:\...\WebSite5\
Error 1 The type or namespace name 'MembershipUser' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Philip\Desktop\WebSite5\LoggedProfile.asp x.cs 19 9 C:\...\WebSite5\

To combat this I add: using System.Web.Security; - Once inserted the code compiles fine with no errors, however shows no content.

My code is as follows. Is it possible I have configured my web.config file wrong, particularly the authentication/forms elements?

Thank you for taking the time to read this if you have gotten this far!


<form id="form1" runat="server">
        <asp:DetailsView ID="UserProfile" runat="server" AutoGenerateRows="False"
            DataKeyNames="UserId" DataSourceID="EmployeeProfileDataSource">
                <asp:BoundField DataField="UserId" HeaderText="UserId" ReadOnly="True"
                    SortExpression="UserId" />
                <asp:BoundField DataField="FirstName" HeaderText="FirstName"
                    SortExpression="FirstName" />
                <asp:BoundField DataField="Surname" HeaderText="Surname"
                    SortExpression="Surname" />
                <asp:BoundField DataField="ContactNumber" HeaderText="ContactNumber"
                    SortExpression="ContactNumber" />
                <asp:BoundField DataField="Office" HeaderText="Office"
                    SortExpression="Office" />
        <asp:SqlDataSource ID="EmployeeProfileDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:EmployeeConnectionString %>"
            SelectCommand="SELECT [UserId], [FirstName], [Surname], [ContactNumber], [Office] FROM [employee] WHERE ([UserId] = @UserId)">
                <asp:Parameter Name="UserId" Type="Object" />


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;

public partial class LoggedProfile : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    protected void EmployeeProfileDataSource_Selecting(object sender,
          SqlDataSourceSelectingEventArgs e)
        // Get a reference to the currently logged on user
        MembershipUser currentUser = Membership.GetUser();

        // Determine the currently logged on user's UserId value
        Guid currentUserId = (Guid)currentUser.ProviderUserKey;

        // Assign the currently logged on user's UserId to the @UserId parameter
        e.Command.Parameters["@UserId"].Value = currentUserId;


<?xml version="1.0"?>
  For more information on how to configure your ASP.NET application, please visit
    <add name="EmployeeConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Philip\Desktop\WebSite5\App_Data\employeedata.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

    <membership defaultProvider="EmployeeSqlMembershipProvider">
        <!--Add a customized SqlMembershipProvider -->
        <add name="EmployeeSqlMembershipProvider"
    <authentication mode="Forms"/>
    <compilation debug="true" targetFramework="4.0"/>

All times are GMT -4. The time now is 08:22 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.