Avatar of nutnut
nutnut
Flag for United Kingdom of Great Britain and Northern Ireland asked on

ASP.NET 2.0 Membership Provider

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
.NET ProgrammingEditors IDEsASP.NET

Avatar of undefined
Last Comment
nutnut

8/22/2022 - Mon
joechina

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.
nutnut

ASKER
Thanks

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

Could you elaborate please

Thank you
SOLUTION
joechina

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
nutnut

ASKER
Thank you

what do you mean by "roles[0] is the company you need."
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
nutnut

ASKER
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
nutnut

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

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
nutnut

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

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.
nutnut

ASKER
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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Reecio

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
nutnut

ASKER
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
Reecio

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
nutnut

ASKER
Great, I'll give that a go,  thank you
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.