.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Accessing Logged In Users Details from MasterPage

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
Hi I have designed a navigation structure that is customisable from within my application and linked to the users role. So I can restrict what menu items a user gets based on their role. I have managed to do this quite well using SQL Tables and an ASP.Net Menu. I can get it to only show the menuitems that are marked active and I have created an Stored procedure to get the menu items for a particular role. Where I am struggling is getting the Logged On Users Roleid to pass it to the Stored Procedure. I can get it using a regular aspx page but my menu is on my masterpage and I do not want to have to code it in each and every page. I even tried to do it with a user-control but same happens.  It seems that the User class is just not available when in a masterpage. Anyone know how I can pass the roleid from a Class or something or from the page to the masterpage? Please Help.   Ronnie 

View Complete Post

More Related Resource Links

Users getting logged out because HttpContext.Current is null


We've  been trying to fix this one for a couple years, and I'm just out of ideas, so any help is really appreciated!

We've got a fairly large, complex web application that uses Forms Authentication to authenticate users.  Throughout the application we store and retrieve information about users in the Session object, and in some cases in cookies.  In a couple places we check for the existence of the context, and if it's null we send the user back to the login page to re-establish the session. 

Just a quick run-down of this web app: C#, .NET 3.5, IIS 6, ASP.NET State Service to manage session

As for the session timer, we use our own home-grown timer, which is basically a client-side timer, which is backed up by a check to the SQL database to see when their last activity was.  This seems to work well for us.  It's not perfect, but it allows us to notify the user before the session times out, and allows us to be certain we're not logging a user out before their 60 minutes of inactivity is up.

What's happening is that certain users are being logged out after just a few minutes.  We've eliminated the timer as a cause and believe what's happening is the HttpContext.Current is null, so the user is logged out.  We do not know why the HttpContext.Current is null, and I underst

Secured web with unauthenticated users accessing a service


hi all,

I have a following configuration:

~/ui/login.aspx, ~/ui/page1.aspx, ~/service/main.asmx

access to web is secured using:

<authentication mode="Forms">
  <forms loginUrl="~/ui/login.aspx" timeout="10" />
<deny users="?" />

but I want to allow unauthenticated users to issue (possibly limited set of) a query to the service (e.g. to display service version on the login page using service call ~/service/main.asmx/GetFullVersion). I'm able to do it locally, but on the server there is a problem and the service cannot be queried. I tried to set

  <location path="~/service/main.asmx/GetFullVersion">
<allow users="*"/>


  <location path="~/service/main.asmx">
<allow users="*"/>


  <location path="

Code to get how many users are logged in to the sharepoint site

How to get the users of my sharepoint who are online.....

Thanx in advance,


Getting Users who logged on in last month

Hi all, Using Sql Server 2005. Is it possible to retrieve from Sql Server the name and times of all users who logged into the server in the last month? Regards Melt

How to allow anyone to see the data, but only logged in users to edit it?

Hello,Don't know if this is documented anywhere, but I haven't found it yet.Let's say I want to allow anyone visiting a site to see the data. That's fairly easy as DD does this for you.However, I don't want just anyone to be able to edit the data. I only want selected people to be able to do that. I presume DD works with forms authentication as I've seen it mentioned, but I ahven't seen how to do it yet. Anyone able to give some pointers?Assuming that I've got authentication, how do I make it so that the public doesn't see an edit or delete link when viewing data?Thanks for any help

FBA users (ldap provider) don't have any user profile info when logged in.... what am I doing wrong

Sharepoint 2010, Claims authentication, FBA using ldap membership provider and role provider against Active Directory.  User profiles all imported just fine -- used the LDAP FBA provider hitting Active Directory to do so too.  whenever an FBA user logs in, it doesn't seem like sharepoint is picking up any user attributes.  targeted audiences don't work and MY SETTINGS is blank other than account and name.  If the same user logs in but through Active Directory, everything works just fine... targeted audiences, etc. Am I doing something wrong or can I not use the LDAP provider to authenticate to AD and also use the user profiles from Sharepoint?  GRRRRR.  All this to get around the Windows Authentication popup so I can customize a better looking logon experience.  Help?

Accessing remote servers details?

Hi friends. How can I access remote server'ss details like RAM details, CPU details etc with a ASP.NET application. I used System.Management class and wmi but the application runs too slow. Is there any another way to do this which is fast and efficient. If this thread is posted in a wrong place, do tell me.   Thanks.

How to find out how many users logged onto a sharepoint hosted site?


We have a sharepoint hosted site that is accessible to users externally. 

Sometimes whenever we need to  release some updates, we would like to do it when there is no user browsing the site.

Are there are any tools available? If not, can we write any scripts or code?

Please suggest.

How to ensure that all users are logged off the sql database and that they can't access when the SQ


We are trying to restore a SQL Server 2005 (all the databases). We have failed with the restore for a couple of times and the vendor says that we have to ensure that all database users are logged off the database. A restore will fail if other users try to use the database while the restore operation is in

How could this be acomplished. There is no way that we can control if any user or app access the server while we are restoring.

The problem is that when when we are restoring the databases if someone access any of them while the restore is taking place the process fails.

The question is how should the restore be performed? Is there any way to change the state of the database so that the databases can be restored?

Any thoughts?

Users being prompted continuously for UN/PW when accessing SharePoint Intranet Site


From time to time, we have internal users who are continuously prompted to re-enter their network username and password when accessing any content or data on the SharePoint company intranet.  We use Acitve Directory authentication. Is this a network issue or something with SP? (We're using SP2007)

securing URL for logged in users


 Hello there ...

I need something to secure my PDF files link ...

i have a page like http......../folder/userName.pdf


i need to to encrypt the file name ( i put it "login userName" ) ...


how do i let logged in users download their pdf files without knowing the URL above , for security reasons only ...

Thank you ...

Are there any way to get the end users machine details from web?


Can we get the end user machine details like machine name, OS name, service pack version, etc., from the web browser. I have tried couple of options,

Have tried using Navigator object. But it doesn't give me the service pack version and other details (since its for the browser).

I am able to get the details using the below snippet,

Set objWshNetwork = CreateObject("WScript.Network")
sLoggedDomainName = Trim(objWshNetwork.UserDomain & "\" & objWshNetwork.UserName)
sLoggedInName = Trim(objWshNetwork.UserName)
'Fetch the computer name
sComputerName = objWshNetwork.ComputerName
Set objWMIService=GetObject("winmgmts:" & "{impersonationLevel=Impersonate}!\\.\root\cimv2")  
Set colSettings = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
   For Each objComputer in colSettings
   Computername= objComputer.Name
temp=Left(Computername, InstrRev(Computername, "|",-1,1)-1)
InstalledOS=Left(temp, InstrRev(temp, "|",-1,1)-1)
ComputerVersion= objComputer.Version
ServicePack= objComputer.ServicePackMajorVersion &"."& objComputer.ServicePackMinorVersion

Assuming identity of other logged in users in web application using Forms Authentication and Singlet



I have a web application with a login form. A user enters a user name and password. If they exist in the database the user is authenticated using these two lines:

FormsAuthentication.SetAuthCookie(userName, false);
FormsAuthentication.RedirectFromLoginPage(userName, false);

The problem is that when a user logs in at first he is logged in as himself. When navigating on the web application for a while the user assumes the identity of another logged in user. This happens all the time.

In my web.config the authentication mode looks like this:

<authentication mode="Forms">
  <forms loginUrl="LogOn.aspx" name=".ASPXFORMSAUTH">
  <deny users="?" />

The site does not use ASP.NET session variables. Instead each page initializes a Singleton class, which stores itself in a static class variable, always accessing the users data already read from the database.

The Singleton implementation is:

static readonly WebSession instance = new WebSession();


public static WebSession GetSingletonInstance
  get { return instance; }

Could the problem with assuming anoth

Limit number of Users accessing the WebService


I am having WSE webservice and i want to limit the users accessing the webservice for example, at a time only 50 users can use that service.

The problem here is the users can vary. We cannot predictate the users. Means, we cannot give authendication for users.

Please help

hide or show CheckBoxList depending on Users logged in profile??



New users can register on my site by completing a basic form that has the create user

wizard control with some additional information i am collecting using a CheckBox List.


They can then log in to the site and and view "MypProfilePage.aspx" where I

display the information with the CheckBoxList boxes already ticked based

their selections which they can update.


My problem is I have two levels of User and each one has a different registration form.

Registration Form A

Has 20 Items in the CheckBox List


Registration Form B

Has 10 items in the CheckBox List


On the Profile Page, I just want to show the  CheckBox which is relevant to the Registration form A or B and with selections by the  registered user.

So therefore the User who registered on B will not be able to see the selections checkbox list for A.


I hope this makes sense and appreciate any solutiosn in c sharp ideally.




accessing sharepoint sitecollection groups, users, roles and displaying them in sqldatabase



I am working on sharepoint groups, users, roles and permissions. my task is to display all groups,users,roles and permissions from a sharepoint sitecollection in sqldatabase table.the table for groups contains following columns ID,Name,Description,OwnerID,Ownerisuser. the table for users contains following columns ID,Name,Sid,LoginName,Email,Isstieadmin,isdomaingroup. the table for roles and permissions is ID,Name,Description,Type,BasePermission. can someone please help with the code. i have started in the following way using a windows application

private void button1_Click(object sender, EventArgs e)
            using (SPSite osite = new SPSite("http://servername//"))
                using (SPWeb oweb = osite.OpenWeb())

--HOW TO -- Only allow logged in users to view Default.aspx, and About.aspx


Hello there guys,

First of all, thank you for the attention.

I am having some trouble, I am very new to asp.net, and the last problem I had, I spent about 59 hours trying to solve, Now I have a new one !

:D well, I guess this is part of the learning process...

Well, in Visual Studio 2010, I clicked New Website. @ C# language, ... The template it gives is pretty nice, it creates a database MDF file, and a login/register setup ready to go !...

You guys can see it live AT CLICK HERE ...

Everything is working, well at least here at the local machine...

There are 2 pages in there, Default.aspX, and About.aspx ... I want to allow ONLY logged in users to view those 2 pages...

I tryed a few things, added my account to a role called ADMIN,

In the web.cong I changed Allow"*" to allow"ADMIN" ... still didn't work..

Also, I was trying to avoid using roles for now, and I was trying to find a way to do this for individual pages in the same directory as well... If possible with out touching the web.config file...

But for now, every way will already help me in any future implementations...

Once again, thank you for your attention..

Thanksssss 10000X

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend