CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > general_asp.net.web_parts_and_personalization Tags:
Item Type: Date Entered: 9/4/2005 12:08:25 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 6 Views: 27 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
"hunterbeta2005
NewsGroup User
Profile Provider and the requirements - reality check9/4/2005 12:08:25 AM

0

It looks like I need to create an additional table in SQL Server 2005 Express to supplement the ?ASPNET_Profile? table already in the database. The out of the box way ASP.NET 2.0 stores custom additional profile property data (FirstName, LastName, ZipCode, etc...) does not meet my project requirements because I can?t figure out how to enable an authenticated user (admin) with the ability to ability to view, edit and update all ?other? users membership and profile data, including the ability to search by a particular custom profile property value (ZipCode value for example) and get a sub-set list of all users with that particular value, then be able to select a user from the returned list and edit/update that users membership and profile data. If there is a way to accomplish this out of the box, please let me know.

S
o, I create an additional profile data table and a profile provider for extended functionality. How do I properly configure the keys in the additional table and the relationships with the existing tables ... and what are the necessary additional table columns needed  (userID, applicationID, etc...) to make sure there is proper functioning of the rest of the out of the box membership, personalization and profile features and the requirements of my project.

I understand I?ll create an additional profile provider to handle getting and setting the custom profile property data into and out of the additional profile data table. I understand how to implement a custom profile provider in web.config. I?m studying up on how to create the class file for the custom profile provider but there are many methods to code for and I?m not a master programmer and I?m running out of time to get this done. What is the minimum code needed to add to a custom profile provider in order to support the following (2) requirements (and I?d really like to at this point be able to get a hold of a complete sample code so all I have to do is update/add the property names and database references).

The custom profile provider needs to be able to support the following (2) project requirements:

1
) enabling an authenticated user with the ability to view, edit and update their own membership, as well as, profile data (FirstName, LastName, ZipCode, etc...), including the ability to change their own UserName.

2) enabling an authenticated user (admin) with the ability to ability to view, edit and update all ?other? users membership and profile data, including the ability to search by a particular custom profile property value (ZipCode value for example) and get a sub-set list of all users with that particular value, then be able to select a user from the returned list and edit/update that users membership and profile data.

Finally, and you guessed it, it would be great if I could get a hold of sample code to build the two above user interfaces.
Thanks for any tips, ideas, suggestions or comments about any detail I mentioned or the approach in general.

"BrockAllen" <>
NewsGroup User
Re: Profile Provider and the requirements - reality check9/5/2005 6:21:40 PM

0

I'd suggest forgetting the built-in profile and just build your own. This means making your own schema and then make the PK column simply the username whose data this is. Also you'll need to make your own class to do the data access to this table and key it off of User.Identity.Name.

-Brock

DevelopMentor
http://staff.develop.com/ballen
"hunterbeta2005
NewsGroup User
Re: Profile Provider and the requirements - reality check9/8/2005 9:57:42 PM

0

Thanks for your suggestion Brock, I think I see how it works now. 

A follow-up question on implementing the "key it off of User.Identity.Name" when making my own class to do the data access on the 'user_profiles' table I made per your suggestion. I'm trying to figure out how to code the GetPropertyValues method of the class and I'm challenged with getting the VB code correct. I'm getting a squiggly under User of User.Indentity.Name - saying User is not declared.

Any tips on how to implement this method correctly?

__________

Public
Overrides Function GetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal ppc As System.Configuration.SettingsPropertyCollection) As System.Configuration.SettingsPropertyValueCollection

D
im connection As SqlConnection

Dim command As SqlCommand

Dim UserNameContext As String

UserNameContext = User.Identity.Name

connection = New SqlConnection("ConnectionString")

command = New SqlCommand("SELECT * FROM User_Profiles " _

& "WHERE UserName = '" _

& UserNameContext & "'", connection)

Dim reader As SqlDataReader

connection.Open()

reader = command.ExecuteReader

While reader.Read()

ppc("ZipCode").DefaultValue = reader("ZipCode")

ppc("FirstName").DefaultValue = reader("FirstName")

ppc("LastName").DefaultValue = reader("LastName")

End While

connection.Close()

End Function
___________

"BrockAllen" <>
NewsGroup User
Re: Profile Provider and the requirements - reality check9/9/2005 3:10:40 PM

0

User is a property off of the Page. If your code is not in a page class then you can use HttpContext.Current.User.Identity.Name.

-Brock

DevelopMentor
http://staff.develop.com/ballen
"hunterbeta2005
NewsGroup User
Re: Profile Provider and the requirements - reality check9/20/2005 9:42:18 PM

0

The following code doesn't work yet, but I know I'm getting close. It's the 'GetPropertyValues" method of a custom profile provider. My mission of the last couple weeks is to find or figure out myself the simplest possible complete working sample code of this method in vb.net, using Visual Web Developer and SQL Express. My Web.config is configured correctly, the database table has UserName as the primary key and a column of 'ZipCode' data. In the code below, the context being read, the reader is reading a row of data - but, I'm getting an error message on the line:

pv.PropertyValue = reader("ZipCode")

.. the error message says, "Invalid attempt to read when no data is present"

I know I'm just like one or two lines of code away from getting this method to work. If anyone knows what those lines of VB.Net code are to complete this task, please let me know what they are, preferrably by writing them out and inserting them into where they need to be in the lines of code below.

Once I figure out how to code a class to perform the task of reading a single custom profile property value from a separate table I create in SQL Express, then I'll figure out how to extend the code to handle multiple custom profile property values. After that, I'll figure out the "SetPropertyValue" method.  Then, I'll have a basic web application that leverages the Provider Design Pattern. I know, I'll need to tweak it out, for example, I've been told the connection string is subject to injection attacks, etc... However, to get to the fine-tuning stage, I need help now implementing the correct VB.Net code in the following simplest possible scenario.

Thanks.

_____

Public
Overrides Function GetPropertyValues(ByVal context As SettingsContext, _

ByVal ppc As SettingsPropertyCollection) _

As SettingsPropertyValueCollection

Dim svc As SettingsPropertyValueCollection = New SettingsPropertyValueCollection()

Dim connection As SqlConnection

Dim command As SqlCommand

Dim username As String = HttpContext.Current.User.Identity.Name

connection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True")

command = New SqlCommand("SELECT [ZipCode] FROM [User_Profiles] " _

& "WHERE UserName = '" _

& username & "'", connection)

Dim reader As SqlDataReader

connection.Open()

reader = command.ExecuteReader

For Each prop As SettingsProperty In ppc

Dim pv As SettingsPropertyValue = New SettingsPropertyValue(prop)

Select Case prop.Name

Case "ZipCode"

pv.PropertyValue = reader("ZipCode")

End Select

svc.Add(pv)

Next

Return svc

connection.Close()

End Function

"BrockAllen" <>
NewsGroup User
Re: Profile Provider and the requirements - reality check9/20/2005 9:50:56 PM

0

You must first call reader.Read() to advance the DataReader to the first row. If this returns false, then it means you have no rows.

-Brock

DevelopMentor
http://staff.develop.com/ballen
"hunterbeta2005
NewsGroup User
Re: Profile Provider and the requirements - reality check9/21/2005 9:51:32 PM

0

Yes, that was it. I wrapped a While Reader.Read() around the For Each loop and my 'GetPropertyValues' method now works. My testing now shows that references to Profile.ZipCode in my .aspx pages will 'get' data from my custom profile table instead of the default aspnet profile table. Thank you. That's a nice victory.

No resting though. I now need to figure out the simplest possible code to 'set' data in my custom profile table via the 'SetPropertyValue' method of my custom profile provider class. I've been working on it myself today to see how far I can take it and I think I've hit a bit of a wall. I can use a few more of your excellent tips if possible.

I started figuring out how to code the SetPropertyValue method by reusing what I know works so far - the code for the GetPropertyValues and tweaking it. That has only taken my so far. 

I know my requirements are to register new users and profiles for the first time and also update existing users profile data - so, the sqlcommand I'll need is INSERT and UPDATE, right? I don't think I need the SELECT command this time.
 
Also, my new users registration process as a requirement to first ask potential new registrants to enter a 'ValidUserCode' into a textbox (and validate it against numbers stored in a separate table of valid codes). When a registrant enters a valid code that code, at the end of the rest of the registration process, becomes part of that users stored profile data. I've already worked out all that, including adding the ValidUserCode as an custom profile property with the anonomous attribute equal to true - and added code to global.asax which acts to remove the anonomous entries in the user and profile tables when that new user is authenticated. That all appears to work using the default profile provider, however, now I need to figure out how to get it to work when I write the data to my custom tables. I've read all the papers describing this and seen all the sample code available so far, but none of the examples simply provide samples in vb.net and in the common usage scenario I've described, including the database reference.

Also, I'm challenged with how to properly declare the parameters and I don't even know if I need the For Each loop or if the DataReader is appropiate for this method.

So, below is the code I have so far that doesn't work, but I've got to start somewhere. Any tips on how to amend the code below to work?

Thanks.
_____

Public Overrides Sub SetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal ppc As System.Configuration.SettingsPropertyValueCollection)

Dim svc As SettingsPropertyValueCollection = New SettingsPropertyValueCollection()

Dim connection As SqlConnection

Dim command As SqlCommand

Dim username As String = HttpContext.Current.User.Identity.Name

connection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True")

command = New SqlCommand("UPDATE [User_Profiles] SET [ValidUserCode] = @ValidUserCode, [ZipCode] = @ZipCode " _

& "WHERE [UserName] = '" _

& username & "'", connection)

command.Parameters.AddWithValue("@ValidUserCode", SqlDbType.VarChar)

command.Parameters.AddWithValue("@ZipCode", SqlDbType.VarChar)

Dim reader As SqlDataReader

connection.Open()

reader = command.ExecuteReader

While reader.Read()

For Each prop As SettingsProperty In ppc

Dim pv As SettingsPropertyValue = New SettingsPropertyValue(prop)

Select Case prop.Name

Case "ValidUserCode"

pv.PropertyValue = reader("ValidUserCode")

Case "ZipCode"

pv.PropertyValue = reader("ZipCode")

End Select

svc.Add(pv)

Next

End While

connection.Close()

End Sub

7 Items, 1 Pages 1 |< << Go >> >|


Free Download:













role based tabs

request of an ascx page from within application

can not login with guest, guest

how can i customize asp.net portal start kit?

tablet pc logoff problem

bug : compiling the portal

image strangeness

admin module

error in htmlmodule

strange caching on tabs

error : input string was not in a correct format.

xp pias xcopy features

links on default.aspx page do not work (portal)

admin function

hi ! i need your help !

setting a default role

try out our new templatable content mangament system

how to put in a module

how do i make a hyperlink in the left pane open up in the content pane

bug

please help datagrid could not show in add new item

i have problems with portal starter kit installing (it can be faq-thread of this forum)

ibs versus dnn ??

having a heck of a time moving the portal to a new host

system.data.sqlclient.sqlexception: login failed for user

allowing multiple roles access to a page

setting property values to a user control

image link error

tree view

creating custom portal modules and then ... server error, specified cast is not valid.

desktopmodules\edithtml.aspx - the directive contains duplicate 'validaterequest' attributes.

setup for portal starter kit failed...

saving portal to a cd/dvd

"~/image/" problem

database connection problem

add an existing module

bug when setting up new user with admins priveledges

skinning

portal starter kit - portal_createdb script

bug: manageusers.ascx

method not found error...get_params()

adding htmlanchor dynamically

where is the siteconfiguration class?

ibuyspy store installation problem

delegate limited admin roles

role based windows authentication question

admin tab

does anyone have adrotator component on portal?

cannot read documentation

smtp send email example

   
  Privacy | Contact Us
All Times Are GMT