Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I designed an asp.net website in which i have created a sign-up and sign-in facility.
Now if a user is signed in than i want that.

Suppose i have 10 pages like home,update, friends update, profile. (these pages do have a lot of functions, methods to perform different tasks etc.)

Now as suppose xyx.com/friends.aspx and xyz.com/update.aspx pages are attached with domain name and these pages have diffrent methods in-built.

I want that only a Logged in user can access these all and all other it should show on the page that...."You need to login <here>".

The mean is i want a completed logged in facility to the users.

Please help me in this regard.

Thanks
Posted

1 solution

Since you are going with domain name, itz pretty simple to fetch the login user info using the below code:
System.Security.Principal.WindowsIdentity.GetCurrent().Name


The above Name property returns the domain user name like 'domainname\\username'.

Now you can strip the user name using the below code:
C#
public static string StripDomain(string userName)
{
int BackSlashIndex = userName.IndexOf("\\");
if (BackSlashIndex != -1)
    return userName.Substring(BackSlashIndex + 1);
else
    return userName;
}


With the validity of the return username, the page is allowed (or not) to display to the logged in user.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900