ASP.NET 2.0 ProfessionalIf you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional 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 .
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.
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:
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: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: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.
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: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.
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).
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.
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.
<asp:Label ID="UserNameLabel" runat="server"
<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."
<asp:DropDownList ID="DropDownList1" runat="server"
[The LoggingIn event of the Login control]
Protected Sub Login1_LoggingIn(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) _
Login1.UserName = CType(Login1.FindControl("DropDownList1"), DropDownList).SelectedValue