473,499 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom MembershipUser and WSAT

I have developed a simple membershipuser class and membershipprovider class.
I basically followed the procedures referenced at
http://msdn.microsoft.com/en-us/library/44w5aswa.aspx and made it even
simpler by inheriting sqlmembershipprovider, and did overrides on only a
couple of methods. So far, they seem to work fine when used in code.
However, I tried using the web site administration tool to edit a user and
received the error below. I am not planning to use WSAT in production; I
just want to make sure something is not wrong with my application. I figured
WSAT would still work (albeit without the additional property) since the
GetUser method returns a CustomMembershipUser which derives from
MembershipUser and should automatically be re-cast to MembershipUser (this
works fine in code when I programmatically get or update users). Any ideas?
Is this expected behavior between WSAT and a customized membershipuser class,
or have I done something wrong?

Could not load type 'CustomMembershipUser' from assembly 'App_Code.n0hgw1qq,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. at
System.Web.Administration.WebAdminPage.CallWebAdmi nHelperMethod(Boolean
isMembership, String methodName, Object[] parameters, Type[] paramTypes) at
ASP.security_users_edituser_aspx.Page_Load() in
c:\Windows\Microsoft.NET\Framework\v2.0.50727\ASP. NETWebAdminFiles\Security\Users\editUser.aspx:line
38 at System.Web.Util.CalliHelper.ArglessFunctionCaller( IntPtr fp, Object o)
at System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender,
EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint)

MembershipUser Class:
---------------------------
Imports Microsoft.VisualBasic

<Serializable()_
Public Class CustomMembershipUser
Inherits MembershipUser

Private _CustId As String

Public Property CustId() As String
Get
Return _CustId
End Get
Set(ByVal value As String)
_CustId = value
End Set
End Property

Public Sub New(ByVal providername As String, _
ByVal username As String, _
ByVal userid As Object, _
ByVal email As String, _
ByVal passwordQuestion As String, _
ByVal comment As String, _
ByVal isApproved As Boolean, _
ByVal isLockedOut As Boolean, _
ByVal creationDate As DateTime, _
ByVal lastLoginDate As DateTime, _
ByVal lastActivityDate As DateTime, _
ByVal lastPasswordChangedDate As DateTime, _
ByVal lastLockOutDate As DateTime, _
ByVal custId As String)

MyBase.New(providername, _
username, _
userid, _
email, _
passwordQuestion, _
comment, _
isApproved, _
isLockedOut, _
creationDate, _
lastLoginDate, _
lastActivityDate, _
lastPasswordChangedDate, _
lastLockOutDate)

Me.CustId = custId

End Sub

End Class

MembershipProvider class:
--------------------------------
Imports Microsoft.VisualBasic
Imports System.Web.Security
Imports System.Data
Imports System.Data.SqlClient

Public Class CustomMembershipProvider
Inherits SqlMembershipProvider

Private pApplicationName As String = "/"
Private conn As SqlConnection = New SqlConnection("Data
Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;
Integrated Security=True; User Instance=True")

'CustomMembershipProvider.UpdateUser
Public Overrides Sub UpdateUser(ByVal user As MembershipUser)
Dim cmd As SqlCommand = New SqlCommand("UPDATE
vw_aspnet_MembershipUsers " & _
" SET Email = @Email, Comment = @Comment," & _
" IsApproved = @IsApproved, CustId = @CustId" & _
" WHERE Username = @Username", conn)

Dim u As CustomMembershipUser = CType(user, CustomMembershipUser)
If u.CustId = Nothing Then u.CustId = ""
If u.Comment = Nothing Then u.Comment = ""
If pApplicationName = Nothing Then pApplicationName = "/"

cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 128).Value = u.Email
cmd.Parameters.Add("@Comment", SqlDbType.NText, 3000).Value =
u.Comment
cmd.Parameters.Add("@IsApproved", SqlDbType.Bit).Value = u.IsApproved
cmd.Parameters.Add("@CustId", SqlDbType.NVarChar, 255).Value =
u.CustId
cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 255).Value =
u.UserName
'cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar,
255).Value = pApplicationName

Try
conn.Open()

cmd.ExecuteNonQuery()
Catch e As SqlException
Throw e
Finally
conn.Close()
End Try

End Sub

' MembershipProvider.GetUser(String, Boolean)
Public Overrides Function GetUser(ByVal username As String, _
ByVal userIsOnline As Boolean) As
MembershipUser

Dim cmd As SqlCommand = New SqlCommand("SELECT Userid, Username,
Email, PasswordQuestion," & _
" Comment, IsApproved, IsLockedOut, createdate,
LastLoginDate," & _
" LastActivityDate, LastPasswordChangedDate, LastLockOutDate,"
& _
" CustId" & _
" FROM vw_aspnet_MembershipUsers WHERE Username = @Username",
conn)

cmd.Parameters.Add("@Username", SqlDbType.VarChar, 255).Value =
username
'cmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar,
255).Value = pApplicationName

Dim u As CustomMembershipUser = Nothing
Dim reader As SqlDataReader = Nothing

Try
conn.Open()

reader = cmd.ExecuteReader()

If reader.HasRows Then
reader.Read()
u = GetUserFromReader(reader)

If userIsOnline Then
Dim updateCmd As SqlCommand = New SqlCommand("UPDATE
vw_aspnet_MembershipUsers " & _
"SET LastActivityDate = @LastActivityDate " & _
"WHERE Username = @Username", conn)

updateCmd.Parameters.Add("@LastActivityDate",
SqlDbType.DateTime).Value = DateTime.Now
updateCmd.Parameters.Add("@Username", SqlDbType.VarChar,
255).Value = username
'updateCmd.Parameters.Add("@ApplicationName",
SqlDbType.VarChar, 255).Value = pApplicationName

updateCmd.ExecuteNonQuery()
End If
End If
Catch e As SqlException
Throw e
Finally
If Not reader Is Nothing Then reader.Close()

conn.Close()
End Try

Return u
End Function

' GetUserFromReader
' A helper function that takes the current row from the SqlDataReader
' and hydrates a MembershiUser from the values. Called by the
' MembershipUser.GetUser implementation.
Private Function GetUserFromReader(ByVal reader As SqlDataReader) As
CustomMembershipUser
Dim Userid As Object = reader.GetValue(0)
Dim username As String = reader.GetString(1)
Dim email As String = reader.GetString(2)

Dim passwordQuestion As String = ""
If Not reader.GetValue(3) Is DBNull.Value Then _
passwordQuestion = reader.GetString(3)

Dim comment As String = ""
If Not reader.GetValue(4) Is DBNull.Value Then _
comment = reader.GetString(4)

Dim isApproved As Boolean = reader.GetBoolean(5)
Dim isLockedOut As Boolean = reader.GetBoolean(6)
Dim creationdate As DateTime = reader.GetDateTime(7)

Dim lastLoginDate As DateTime = New DateTime()
If Not reader.GetValue(8) Is DBNull.Value Then _
lastLoginDate = reader.GetDateTime(8)

Dim lastActivityDate As DateTime = reader.GetDateTime(9)
Dim lastPasswordChangedDate As DateTime = reader.GetDateTime(10)

Dim lastlockoutdate As DateTime = New DateTime()
If Not reader.GetValue(11) Is DBNull.Value Then _
lastlockoutdate = reader.GetDateTime(11)

Dim custId As String = String.Empty
If reader.GetValue(12) IsNot DBNull.Value Then _
custId = reader.GetString(12)

Dim u As CustomMembershipUser = New CustomMembershipUser(Me.Name, _
username, _
Userid, _
email, _
passwordQuestion, _
comment, _
isApproved, _
isLockedOut, _
creationdate, _
lastLoginDate, _
lastActivityDate, _
lastPasswordChangedDate, _
lastlockoutdate, _
custId)

Return u
End Function

End Class

web.config membership section:
-------------------------------------
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear />
<add connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/" requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
name="CustomMembershipProvider"
type="CustomMembershipProvider" />
</providers>
</membership>

Jun 27 '08 #1
0 1600

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1956
by: WB | last post by:
Hi, I am revamping my company's website using .Net 2.0 & C#. I would like to implement my own custom membership provider to manage membership information already stored in my existing SQL 2000...
8
5414
by: Mark Olbert | last post by:
I'm writing a custom MembershipProvider which uses a custom class derived from MembershipUser (basically, the derived class adds a field to the MembershipUser base class). When I try to configure...
9
1782
by: Mark Olbert | last post by:
I'm reposting this in case it got lost... The ASPNET Configuration tool does not appear to be able to handle derived MembershipUser classes. Even the simplest possible derived class (one which...
3
1876
by: Jeff | last post by:
Hey ASP.NET 2.0 I'm trying to extend the MembershipUser class, and have encounter a problem: << See in the middle of this post for info about why I do this >> << See below of this post for...
0
1554
by: Fendi Baba | last post by:
I need to implement a login system using Asp.net 2.0 login module( membership provider) with password being case insensitive. I wrote a class Accessmembershipprovider.vb and below is my code....
4
4727
by: freeflytim | last post by:
I'm trying to implement a custom MembershipProvider (and RoleProvider) together with a custom MembershipUser class in C#, Asp.Net 2.0, MS Visual Studio 2005. Everything has worked fine so far,...
0
978
by: Marcin Nowak | last post by:
Hi, I am using .NET 2.0 (on IIS6, Win2003 Srv), and I want to configure access to my web application direcories with Web Site Administration Tool. The direcories are in my virtual directory and...
0
1813
by: =?Utf-8?B?QmVuIEhvbHRzY2xhdw==?= | last post by:
I am trying to use the web site administration tool to configure roles for my site. Everything is on my local machine, and I am launching WSAT from Visual Studio's Project menu. WSAT works fine...
0
1079
by: steven | last post by:
Hi We want to use the Web Site Administration Tool to manage all our sites. However, it seems that WSAT always looks for a separate copy of aspnetdb in each site's app_data folder. Is there a...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.