We help IT Professionals succeed at work.

ASP.NET 2.0 Membership Provider

532 Views
Last Modified: 2013-11-07
Hi,

I am developing a website that Companies will sign up too.  Each company will have several employees that will have a UserId to view only their companies data.  

So for example:

CompanyA has EmpA1 and EmpA2
CompanyB has EmpB1 and EmpB2

EmpA1 logs on and I need a Session Variable to be populated with CompanyA
EmpA2 logs on and I need a Session Variable to be populated with CompanyA
EmpB1 logs on and I need a Session Variable to be populated with CompanyB
EmpB2 logs on and I need a Session Variable to be populated with CompanyB

Plan is I will then use the session variable within all the SQL statements so WHERE Company = [SessionVariable] to display the data to the logged on Employee.

What is the best way to accomplish this using ASP.NET Membership.  Is this the best way.  I have heard about subdomains, what are they and would they work for me?  


Regards

nutnut
Comment
Watch Question

Commented:
You could enable role management with ASP.NET membership
When a company signs up, you create a new role and a new company level admin user id.
Individual employee is added by creating a new user id and assigned to the company role.

Author

Commented:
Thanks

and how would I assign a company to a session variable from a logon usedid?

Could you elaborate please

Thank you
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you

what do you mean by "roles[0] is the company you need."

Author

Commented:
what would I do if I needed an employee to be in an Admin Role or Standard Role also, so more than one role?

cheers

Author

Commented:
would using profiles be better for this do you think??  Sorry I'm very new to this  Thanks

Commented:
Dont think you want Memberships, try using profiles. Assign a property to the user that holds the company ID of the company they are associated with, then all you need to do is apply a filter to the datasource that you're pulling the data with and filter by company ID.

You can then reference it in you code by putting Profile.CompanyID or in datasources, when you define your parameters, you can select profile from the pull down and type CompanyID as the property name.

Profile info can be found here http://msdn.microsoft.com/en-us/magazine/cc163724.aspx

Author

Commented:
Sounds great Reecio but could you elaborate please with an example perhaps, this would be extremely helpful to me...thank you

Commented:
Certainly, you need to define the property's in the config.web file like so:

Where MyProviderConnection is the name of the connectionstring you connect to your .net database (contains all the asp_net tables) with and AppName is only really required if you run multiple programs with the same database.


     
       
     

     
       
       
       
          etc....
     


Then you can refer to it as I mentioned above.
Please note, if you want a specific data type you must specify it as above, string types dont need to be defined as they are default.

Also you might want to know how to set up a profile (once its defined) for a user, its just:

[Pretending i've set up controls from Name, DoB and a dropdown for CompanyID]
Dim NewProfile As ProfileCommon = ProfileCommon.Create(NewUser.UserName)
        NewProfile.Name = Name.Text
        NewProfile.DoB = CDate(DoB.text)
        NewProfile.CompanyID = Company.SelectedValue
        NewProfile.Save()

Let me know if you require any more assistance.

Author

Commented:
Reecio Great answer thanks

Is

Dim NewProfile As ProfileCommon = ProfileCommon.Create(NewUser.UserName)
        NewProfile.Name = Name.Text
        NewProfile.DoB = CDate(DoB.text)
        NewProfile.CompanyID = Company.SelectedValue
        NewProfile.Save()

how to set up a Session Variable not sure what this bit is doing plus not sure what " ProfileCommon.Create(NewUser.UserName)" bit is?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Joechina - Thanks for the tips

Reecio - Great answer!  thank you very much this has helped me tremendously.....

Any code on "(In my program its attached to a createuser control that i've modified so that the profile is created directly after the user is added to the db)." would be great too if you have it. Cheers

nutnut

Commented:
nutnut, you simply put the ProfileCommon.create code in the createduser event of the createuser control.
Switch the control in to template view and add your own controls, then assign the values of those controls to each of the profile properties before you save them. Thats it really.

Reece

Author

Commented:
Great, I'll give that a go,  thank you
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.