• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

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.

regards,
0
shah36
Asked:
shah36
  • 2
2 Solutions
 
RannyMeierCommented:
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));
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["login"] = @"sal_chc_mta\username";
dt.Rows.Add(dr);
string currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (dt.AsEnumerable().Any (d => d.Field<string>("login") == currentUser))
{
	Debug.WriteLine("true");
}
else
{
	Debug.WriteLine("false");
}

Open in new window


Your database query will likely be different than this example.

Ranny
0
 
RannyMeierCommented:
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.

Ranny
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now