Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 9th, 2013, 12:34 PM
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!

Code:
<form id="form1" runat="server">
    <div>
    
        <asp:DetailsView ID="UserProfile" runat="server" AutoGenerateRows="False"
            DataKeyNames="UserId" DataSourceID="EmployeeProfileDataSource">
            <Fields>
                <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" />
            </Fields>
        </asp:DetailsView>
    
        <asp:SqlDataSource ID="EmployeeProfileDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:EmployeeConnectionString %>"
            SelectCommand="SELECT [UserId], [FirstName], [Surname], [ContactNumber], [Office] FROM [employee] WHERE ([UserId] = @UserId)">
            <SelectParameters>
                <asp:Parameter Name="UserId" Type="Object" />
            </SelectParameters>
        </asp:SqlDataSource>
Code:
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;
    }
}
Code:
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <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"/>
  </connectionStrings>
  <system.web>

    <membership defaultProvider="EmployeeSqlMembershipProvider">
      <providers>
        <!--Add a customized SqlMembershipProvider -->
        <add name="EmployeeSqlMembershipProvider"
        type="System.Web.Security.SqlMembershipProvider"
        connectionStringName="EmployeeConnectionString"
        enablePasswordRetrieval="false"
        enablePasswordReset="true"
        requiresQuestionAndAnswer="true"
        applicationName="SecurityTutorials"
        requiresUniqueEmail="true"
        passwordFormat="Hashed"
        maxInvalidPasswordAttempts="5"
        minRequiredPasswordLength="7"
        minRequiredNonalphanumericCharacters="1"
        passwordAttemptWindow="10"
        passwordStrengthRegularExpression=""/>
      </providers>
    </membership>
    <authentication mode="Forms"/>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
</configuration>
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 07: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



All times are GMT -4. The time now is 07:17 AM.


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