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>