Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim C 161 posts 528 karma points
    Jun 06, 2016 @ 17:37
    Tim C
    0

    I have written a web service in an asmx file (stored under Umbraco\WebServices) and use methods I have in a class in a separate cs file.

    I would like to access the Umbraco loggedin user id - so in my calls I am

    using Umbraco.Core.Security;
    using Umbraco.Core.Models.Membership;
    

    ...

    var authenticationTicket = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
            IUser user = null;
            if (authenticationTicket != null)
            {
                user = UmbracoContext.Current.Application.Services.UserService.GetByUsername(authenticationTicket.Name);
            }
            else
            {
                // not logged into backoffice
            }                       
    
            // use it if not null
            var lUserId = "";
            if(user != null)
            {
    
                lUserId =  user.Id.ToString();
    
            }
    

    This is actually returning the logged in user, which suggests that the web service is part of the main application session and has access to HttpContext.

    My question is - is this reliable, ie is the web service always going to be able to query HttpContext, or is this going to be flaky?

Please Sign in or register to post replies

Write your reply to:

Draft