Using the code below to retrieve the current backoffice user, the user appears to be logged in within the view of the backoffice but not logged in on the front end.
public static IUser GetCurrentUser() {
string userName = "";
var auth = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
if (auth != null) {
userName = auth.Name;
}
return ApplicationContext.Current.Services.UserService.GetByUsername(userName);
}
The function is called from a custom dashboard.aspx file and when it displays in the backoffice the user details available but not when the dashboard.aspx file is called directly through the browser. Relevant lines from dashboard.aspx:
protected void Page_Load(object sender, EventArgs e) {
var CurrentUser = Helpers.CustomUmbracoHelper.GetCurrentUser();
if (CurrentUser != null) {
// 1 is admin type, 5 is site admin type
if (CurrentUser.UserType.Id == 1 || CurrentUser.UserType.Id == 5) {
// ok to proceed
pnlAdminView.Visible = true;
pnlNonAdminView.Visible = false;
}
}
}
I should mention that this same code is working on another site and this is a slightly modified version of that site.
Still seeing the same issue. I took at the log and I'm seeing something that might be causing the issue... but not sure what's causing that or the fix. Here's the log entries:
2018-06-01 15:46:53,653 [P22024/D2/T20] ERROR Umbraco.Core.Security.AuthenticationExtensions - The current identity cannot be converted to Umbraco.Core.Security.UmbracoBackOfficeIdentity
System.InvalidOperationException: Cannot create a Umbraco.Core.Security.UmbracoBackOfficeIdentity from System.Security.Claims.ClaimsIdentity since the required claim http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier is missing
at Umbraco.Core.Security.UmbracoBackOfficeIdentity.FromClaimsIdentity(ClaimsIdentity identity)
at Umbraco.Core.Security.AuthenticationExtensions.GetCurrentIdentity(HttpContextBase http, Boolean authenticateRequestIfNotFound)
2018-06-01 15:47:01,238 [P22024/D2/T20] ERROR Umbraco.Web.WebApi.Filters.AngularAntiForgeryHelper - Could not validate XSRF token
System.Web.Mvc.HttpAntiForgeryException (0x80004005): The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the
Backoffice user not logged in on front end
Using the code below to retrieve the current backoffice user, the user appears to be logged in within the view of the backoffice but not logged in on the front end.
The function is called from a custom dashboard.aspx file and when it displays in the backoffice the user details available but not when the dashboard.aspx file is called directly through the browser. Relevant lines from dashboard.aspx:
I should mention that this same code is working on another site and this is a slightly modified version of that site.
Hi Simon
I'm not sure exactly what you're doing here, but maybe this will help you.
https://codeshare.co.uk/blog/how-to-get-the-current-logged-in-umbraco-user-and-restrict-front-end-content/
Kind regards
Paul
Your link is only a rehash of the code I'm already using.
Still seeing the same issue. I took at the log and I'm seeing something that might be causing the issue... but not sure what's causing that or the fix. Here's the log entries:
2018-06-01 15:46:53,653 [P22024/D2/T20] ERROR Umbraco.Core.Security.AuthenticationExtensions - The current identity cannot be converted to Umbraco.Core.Security.UmbracoBackOfficeIdentity System.InvalidOperationException: Cannot create a Umbraco.Core.Security.UmbracoBackOfficeIdentity from System.Security.Claims.ClaimsIdentity since the required claim http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier is missing at Umbraco.Core.Security.UmbracoBackOfficeIdentity.FromClaimsIdentity(ClaimsIdentity identity) at Umbraco.Core.Security.AuthenticationExtensions.GetCurrentIdentity(HttpContextBase http, Boolean authenticateRequestIfNotFound)
2018-06-01 15:47:01,238 [P22024/D2/T20] ERROR Umbraco.Web.WebApi.Filters.AngularAntiForgeryHelper - Could not validate XSRF token System.Web.Mvc.HttpAntiForgeryException (0x80004005): The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the
Any ideas?
Bump
is working on a reply...