How do you know that you are logged in to a Sharepoint webpage?

We use Sharepoint as a CMS for our web pages at work. I know how to create controls that can only be visible if you are logged in to SharePoint using:

<Sharepoint: SPSecurityTrimmedControl ID = "SPSecurityTrimmedControl1" Runat = "Server" PermissionsString = "AddAndCustomizePages"> <br />
<Sharepoint: CssLink ID = "CssLink1" runat = "server" />
<br /> </ Sharepoint: SPSecurityTrimmedCont

But I want to know how to make the controls visible (or something else) programmatically depending on the permissions.

I cannot use methods for Windows authentication in the form of .NET:

        if (!(HttpContext.Current.User == null) && HttpContext.Current.User.Identity.IsAuthenticated){}

because we use it for anonymous users who have a different type of login.

Could you provide the code? I know this should be something like checking for SPContext.Current.FormContext.

+3
source share
3 answers

How do users authenticate? Using forms authentication or a Windows / active directory?

If the active directory, then I think that in this case you may need a link to the current SPWeb, and then make web.CurrentUser.ID. It can turn out null when you are anonymous. If not, try web.SiteUsers.GetByID (web.CurrentUser.ID) and see what you get.

+4
source

DoUserHavePermissions

, , .

, , , , .

+1

Although I have not tested it, I believe that the LoginName property of the SPUser object will be empty or throw an exception.

... of course, you should never hope for anything when working with SharePoint OM :(

0
source

All Articles