StrataFrame Forum

Set Form Based on CurrentUser/Role

http://forum.strataframe.net/Topic14637.aspx

By Bill Cunnien - 3/1/2008

In order to do what I wanted to do I utilized the ShowGateway() method in the program.cs.  I added two forms to the collection in InitApplication.  Then I added the following code to the ShowGateway method:

if (System.Environment.MachineName != "COMPNAME")
{
    e.FormIndexToShow = 0;
}
else
{
    e.FormIndexToShow = 1;
}

This does work.  My actual code involves a little more string manipulation in order to limit the number of workstations to three that get FormIndex 1; however, if I logged on to those workstations as myself (an admin), it would be nice to get the general window (index 0).  That won't happen, though.  Only the one form will be displayed. 

So, here is my question:  how do I set the main form based on the current logged in user name or a role assigned to that user?

Thanks,
Bill

By Teddy Jensen - 3/1/2008

Hi Bill,

In your own example instead of System.Environment.MachineName i am pretty sure you can do System.Environment.UserName, which  returns the logged on user on the machine.

Then you can extend your users table (or create a new table with additional userinfo and link it to the users table)  with info on which form to load on startup.

Then you should be able to read the user, query your field with forminfo for that user and show the returned form.

/Teddy

By StrataFrame Team - 3/3/2008

Teddy is right about the currently logged in Windows user, and if that's what you're looking for the, that will take care of it. 

If you're looking for the current logged in StrataFrame user, you can get access to the username through the MicroFour.StrataFrame.Security.SecurityBasics.CurrentUser.Username property.  However, the ShowGateway gets called before the ShowLoginAndInitMainForm, so you will want to just move your code that shows the login form to the ShowGateway just like you would have it in the ShowLoginAndInitMainForm method.

By Bill Cunnien - 3/3/2008

Teddy and Ben,

Thanks!  The UserName from the System.Environment namespace is exactly what I needed.  I am setting the SF Current User to the AD User, so they are the same after authentication is settled.

Have a good day!
Bill