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