I'm implementing the CK Finder file manager with Umbraco, and I need to check if the user is authenticated before I give them access. I've found loads of examples of how to check for authentication in xslt, but none in a C# user control. I'm guessing its fairly simple - this is as close as I got: umbraco.library.isloggedOn()
I've tried both of those and they are still returning false. I'm testing it within the 'umbraco/plugins/tinymce3/insertLink.aspx' popup that is accessed via the tinyMCE interface. For testing purposes I'm just trying to write the value into the HTML using this code:
hm, i'm not sure if those methods are supported when working in the backend. also think both aaron and paul were thinking you're integrating that file manager in the front end of the site (which is where the membership stuff becomes more relevant)
users and members are two completely different concepts in umbraco. users are used to access the admin backend whilst members are people that have registered with your site and get privileges based on their roles.
so, i'm thinking you'll need to have a closer look at users, and what api is available in that area...
If you want to retrieve the current User in the backend you can use the static method
User.GetCurrent()
I think this is supported from 4.0.2.1. Not sure. But in the Backend you should always be logged in isn't it? I've used this method to check if a user has access to a certain application.
Yeah I was assuming that you were looking at front-end not back-end, but it *should* work, I'll check tomorrow as back-end users are also ASP.NET Membership provider based so it should have worked... should have :P
Richard - I tried your piece of code, it returned the following error:
CS1061:
'System.Security.Principal.IPrincipal' does not contain a definition
for 'GetCurrent' and no extension method 'GetCurrent' accepting a first
argument of type 'System.Security.Principal.IPrincipal' could be found
(are you missing a using directive or an assembly reference?)
Do I need to cast the User as a type that is used within Umbraco?
C# code to check if the user is logged on
I'm implementing the CK Finder file manager with Umbraco, and I need to check if the user is authenticated before I give them access. I've found loads of examples of how to check for authentication in xslt, but none in a C# user control. I'm guessing its fairly simple - this is as close as I got: umbraco.library.isloggedOn()
Anybody know how? Thanks.
You can do this via the ASP.NET Membership:
http://msdn.microsoft.com/en-us/library/system.security.principal.iidentity.isauthenticated.aspx
I have been using this:
if (Membership.GetUser() != null)
{
...
}
I've tried both of those and they are still returning false. I'm testing it within the 'umbraco/plugins/tinymce3/insertLink.aspx' popup that is accessed via the tinyMCE interface. For testing purposes I'm just trying to write the value into the HTML using this code:
<%="test=" + (Membership.GetUser() != null)%>
hm, i'm not sure if those methods are supported when working in the backend. also think both aaron and paul were thinking you're integrating that file manager in the front end of the site (which is where the membership stuff becomes more relevant)
users and members are two completely different concepts in umbraco. users are used to access the admin backend whilst members are people that have registered with your site and get privileges based on their roles.
so, i'm thinking you'll need to have a closer look at users, and what api is available in that area...
cheers,
/Dirk
If you want to retrieve the current User in the backend you can use the static method
I think this is supported from 4.0.2.1. Not sure. But in the Backend you should always be logged in isn't it? I've used this method to check if a user has access to a certain application.
Cheers,
Richard
Yeah I was assuming that you were looking at front-end not back-end, but it *should* work, I'll check tomorrow as back-end users are also ASP.NET Membership provider based so it should have worked... should have :P
Richard - I tried your piece of code, it returned the following error:
CS1061: 'System.Security.Principal.IPrincipal' does not contain a definition for 'GetCurrent' and no extension method 'GetCurrent' accepting a first argument of type 'System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?)
Do I need to cast the User as a type that is used within Umbraco?
I found the solution after digging around google a bit more, it checks if the back-end umbraco user is authenticated:
if (umbraco.BasePages.UmbracoEnsuredPage.CurrentUser != null)
Great,
Still strange that the User.GetCurrent doesn't work. why is it made static then? Thanks for your feedback
Cheers,
Richard
User.GetCurrent works fine in a User Control in v 4.0.2.1
Yes, it's implemented in 4.0.2.1 so that should work ;-)
is working on a reply...