p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   I need suggestion about user accounts (http://p2p.wrox.com/showthread.php?t=46033)

hcusto August 2nd, 2006 08:06 AM

I need suggestion about user accounts
 
Hi,
I am working for a few years as php/mysql programmer, and becouse of my new work I need to use .NET.

So I am learning C# and learning to use Visual studio.

Right now i am in doubt what should I use (should I create my custom Membership Provider, or create tables (useres,roles) with my required fields and create functions which will check is password provided during the login correct and similar)

Reasons why i am not using login controls is this (I don't know is my reason reasonable becouse I am new to all this stuff)

1. Now we are working on SQL Express database, but at the end of the project, we will use Oracle DB.

2. Tables which I get when I run file(I don't know the name of file, but it is in DOT Net Framework folder and it creates tables in databese for using SQLExpress membership provider, it's some exe file) and it creates a lot of tables which I don't want to use, i need only Users, Roles tables.

3. I must save more informations then I can right now (the columns that i need (like: Newsletter, SpecialOffers etc ) don't exists in tables)

So please give me some suggestions what should i do.

Best regards,
Haris


hcusto August 5th, 2006 12:42 PM

No one can help me ?


Imar August 6th, 2006 04:34 AM

Hi there,

First of all, when you run aspnet_regsql it does indeed create a lot of tables by default. However, if you run the tool from a command line, you can specify what features you want to support. Type aspnet_regsql /? for more info.

I don't think it's a good idea to work with SQL Express now if your intention is to switch to Oracle. I think you'll run into a lot of problems with incompatible code when you make the switch.

Writing your own provider is not that hard. And the main benefit of your own provider is that you can easily rewrite the code so it works with Oracle. Take a look here for some suggestions about creating your own provider:

http://Imar.Spaanjaars.Com/QuickDocId.aspx?quickdoc=380

I am not sure, but I wouldn't be surprised if there were already Oracle providers.

If you want to store some additional info besides the (default) user tables, maybe this helps:

http://weblogs.asp.net/scottgu/archi...18/427754.aspx

With this solution, you can use the standard Login features offered by .NET 2.0 and store additional info in the Profile object.

However, all of this will only work out of the box with a SQL Server database, not with Oracle.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.

hcusto August 8th, 2006 04:07 AM

Thnx for your help, i will try to create custom membership provider.

Becouse I am new to all of this stuff about provider model, i have a couple of questions.

1. Where is stored profile data (becouse there are no rows in the table users for profile data)

2. How can i have a list of all users which have same let say country

3. I want to create my login form, i don't want to use "Login Control". How can i solve that

Thanx in advance.
Haris


Imar August 8th, 2006 04:18 AM

Quote:

quote:3. I want to create my login form, i don't want to use "Login Control". How can i solve that
In that case, why bother with a custom provider? Why don't you write your own logic to validate users? The whole idea about a provider (custom or out-of-the-box) is that you can use controls like Login without any additional code. If you don't want to use those controls, I don't see much point in writing a provider.

Quote:

quote:1. Where is stored profile data (becouse there are no rows in the table users for profile data)
Normally, it's stored in the aspnet_Profiles table in your database.

Quote:

quote:2. How can i have a list of all users which have same let say country
This is not something the provider model offers out of the box. You can write the required functionality yourself, and expose it as additional members on your custom providers (e.g. FindUsersByCountry, similar to FindUsersByEmail), or if you don't write a provider through a custom class / API.

Cheers,

Imar

hcusto August 9th, 2006 03:15 AM

Honestly, I don't know on which way to do this. So i have posted my question here.

Before when i was using php/mysql i have to create everything, and i have don'e that.

Now, becouse i am new to asp.net i asked you what to do. Should i use the same way as I do with php/mysql (creating everything) or should i use User Profiles in .net



Imar August 10th, 2006 01:34 AM

Hi again,

The answer is of course: it depends.... ;)

Personally, I would use the new Login controls and provider model. These features add a lot of functionality without requiring any custom code.

However, you seemed to have made up your mind already:
Quote:

quote:I want to create my login form, i don't want to use "Login Control".
Is there a reason you don't want to use these controls? They are highly customizable (for example, you can control the entire HTML they render) and can save you a lot of work.

If you don't want to use these controls and don't want to use the provider model, indeed the way to go is how you did it earlier: create your own form, gather user details, submit them to a database and validate the user.

Personally, I would investigate the out-of-the-box features of ASP.NET 2 once more and see if they are useful to you. Might save you from a lot of work.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.

hcusto August 18th, 2006 04:07 AM

As you say, i did some reserchas about ASP.NET 2.0 controls , and I am now using Login Control and it's working great. I will now start a new topic becouse i need some help with accessing users profile values (for all users).

Thnx for this help Imar,
Haris


saf November 29th, 2006 03:25 PM

Hi again Imar -

I've been searching for days to see if this is possible and don't think it is but thought I'd check with you first -

I want to use the Login Control and provider models but I also want to provide a dropdown list of usernames for login. Let me explain my situation so you know what I'm talking about.

I am creating an orders database. In order to gain initial access to the system, each person will login using their name and a password that will be provided to them when their administrator signs on with my website.
So the initial security is loose, as long as the administrator gives out the password user will get to their main order form. Anyone who logs in this way will be assigned to a role and authenicated throughout the system based on that role, so that they can only access their own form.

So I will have many users logged in with the same username at one time which I don't think will be a problem. Only users that will login with a username will be the administrators and this will be done once they get passed the inital login.

I guess all I'm asking is whether there is any way to customize the login username text field to use a dropdown list. I'm pretty sure I read somewhere that it has to be a textbox.

If not I'm sure there is an easy way to do this only I can't seem to get it to work. Like I said, I would really like to use all the role/membership functionality already set up with asp.net to authenticate my users once they get to their main page.

Thanks!

Imar December 2nd, 2006 09:14 AM

Hi saf,

If I understand you correctly, this can be done, and it isn't too hard. Here's what you should do:

1. Add a Login control to the page and convert it to a template (on its Task pane)

2. Hide the table cell that holds the UserName textbox using runat="server" and visible="false". The login control checks to see if there is a UserName so you can't remove it, but hiding does the trick.

3. Add a new table cell to replace the text box and add a drop down control.

4. Add an ObjectDataSource control with its TypeName set to System.Web.Security.Membership, its SelectMethod to GetAllUsers and its DataObjectTypeName set to MembershipUser.

5. Hook up the DropDownList to the ObjectDataSource control by setting the DataSourceID to the ID of the ODS and set both DataTextField and DataValueField to UserName.

6. When you now run the page, you get a nice drop down list with all the user names in the system, instead of the original user name textbox.

7. The final step is to fill the UserName property of the Login control with the selected value of the dropdown list. You can do this in the LoggingIn event of the Login control. You need to "find" the DropDownList and then cast it properly, retrieve its SelectedValue and assign it to the UserName of the Login.

This way, a user can select a name from the drop down. When they click the Login button, the selected user is passed to the authentication process.

You'll find the relevant bits of code below.

Hope this helps.....

[ODS control in the Login page]
Code:

<asp:ObjectDataSource ID="ObjectDataSource1"
  DataObjectTypeName="MembershipUser" runat="server"
  SelectMethod="GetAllUsers"
  TypeName="System.Web.Security.Membership">
</asp:ObjectDataSource>

[Login control with DDL and hidden text box]
Code:

<tr>
  <td align="right">
    <asp:Label ID="UserNameLabel" runat="server"
        AssociatedControlID="UserName">User Name:</asp:Label>
  </td>
  <td runat="server" visible="false">
    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
        ControlToValidate="UserName" ErrorMessage="User Name is
             required." ToolTip="User Name is required."
        ValidationGroup="Login1">*
    </asp:RequiredFieldValidator>
  </td>
  <td>
    <asp:DropDownList ID="DropDownList1" runat="server"
       DataSourceID="ObjectDataSource1" DataTextField="UserName"
       DataValueField="UserName"></asp:DropDownList>
  </td>
</tr>

[The LoggingIn event of the Login control]
Code:

Protected Sub Login1_LoggingIn(ByVal sender As Object, _
      ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) _
      Handles Login1.LoggingIn
  Login1.UserName = CType(Login1.FindControl("DropDownList1"), DropDownList).SelectedValue
End Sub

Please let me know if this works for you.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.


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

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