How to Authorize the logged in user

Hi there,

I am trying to write a programme to capture the current domain user(sal_chc_mta\username) and then matches it with the login  column of the table (sal_chc_mta\username) and if the user is there in the table it redirects to a page and if not it redirects to another page.

i want a very secure method.

can you please help me.

Ali ShahSQL DeveloperAsked:
Who is Participating?
RannyMeierConnect With a Mentor Commented:
Hi shah36,
Me again.  My previous post is a specific answer to your question if your program is running on Windows.  Now as your question mentions "page", then maybe your application is a Web application.  If yours is a web application, then maybe it is to run on Windows IIS.  If that is the case then there are Authentication methods such as Forms Authentication and Windows Authentication built in that can use Active Directory.

RannyMeierConnect With a Mentor Commented:
Hi shah36,
I think that System.Security.Principal.WindowsIdentity.GetCurrent().Name is the method that can help.  For example:

DataTable dt = new DataTable();
DataColumn dc = new DataColumn("login", typeof(string));
DataRow dr = dt.NewRow();
dr["login"] = @"sal_chc_mta\username";
string currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (dt.AsEnumerable().Any (d => d.Field<string>("login") == currentUser))

Open in new window

Your database query will likely be different than this example.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.