Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET 4 : in C# and VB
BOOK: Professional ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Professional ASP.NET 4 in C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470502204
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 9th, 2013, 12:34 PM
Registered User
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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"/>

Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Out My Blog for Updates and Additional Information John Mueller BOOK: Professional Windows 7 Development Guide 0 March 11th, 2011 03:42 PM
Storing data in HttpContext, concurrency issue jlrolin ASP.NET 2.0 Professional 0 March 30th, 2008 06:25 PM
storing user input brainchild Javascript 2 March 1st, 2007 04:55 AM
Examples of storing user info from db in profiles? bpdsmark ASP.NET 2.0 Basics 0 March 11th, 2006 03:13 PM
user login information Tee88 Classic ASP Basics 2 November 11th, 2005 10:21 AM

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