locked
Lightswtich HTML deployed as Azure Website + Windows Azure Active Directory RRS feed

  • Question

  • I'm trying to implement Windows Authentication in a newly created Lightswitch HTML application hosted in Windows Azure as a Web Site. After creating the Active Directory and the application and following the steps provided in the blog entry refered in the portal, I have managed to get the login page and perform the validation. But, once I'm back at the HTML website, I get a 500 error for every request.

    In order to test the validation, I've created a generic handler which simply returns the username:

    public void ProcessRequest(HttpContext context)
    {
        using (var serverContext = ServerApplicationContext.CreateContext())
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(serverContext.Application.User.Name);
        }
    }
    

    and disabled customErrors and managed to get error details:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Microsoft.LightSwitch.Utilities.Server.Internal.ServerRequestSecurityState.GetSecurityGroupsForCurrentUser(IWindowsIdentity identity) +20
       Microsoft.LightSwitch.Utilities.Server.Internal.ServerRequestSecurityState.GetEffectiveRolesForUser(IIdentity identity, IEnumerable`1 currentRoles, Func`3 getRoles) +687
       Microsoft.LightSwitch.Utilities.Server.Internal.ServerRequestSecurityState.GetEffectiveRolesForUser(IIdentity identity, IEnumerable`1 currentRoles) +121
       Microsoft.LightSwitch.Security.ServerGenerated.Implementation.SecurityDataProvider.GetUserData(IPrincipal principal) +305
       Microsoft.LightSwitch.Security.ServerGenerated.Implementation.SecurityDataProvider.CreateUser(IPrincipal principal) +18
       Microsoft.LightSwitch.Security.ServerGenerated.Implementation.SecurityInfo.CreateUser(IPrincipal principal) +7
       Microsoft.LightSwitch.Utilities.Server.Internal.SecurityHelper.ConvertPrincipal(IPrincipal principal) +184
       Microsoft.LightSwitch.Framework.Server.ServerApplication`2.get_User() +166
       LightSwitchApplication.Web.GetUserName.ProcessRequest(HttpContext context) +144
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
    

    I don't know if there is something I'm missing or that maybe, this scenario (Lightswitch in Azure Web Site + Azure AD) is not supported by Lightswtich at this moment

    Sunday, January 5, 2014 8:45 AM

Answers

  • Hi Farlop

    >NullReferenceException: Object reference not set to an instance of an object.

    According to the error message above, there is something missing procedures, I can hardly give precise troubleshooting, it's recommended to follow the steps, and have a try again.  Make sure you have prerequisites required to complete that tutorial.

    At the same time it's also recommended to get help from Windows Azure forum, more Azure experts can help you there.

    Best regards

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Angie Xu Wednesday, January 15, 2014 6:52 AM
    Monday, January 6, 2014 7:45 AM

All replies

  • Hi Farlop

    >NullReferenceException: Object reference not set to an instance of an object.

    According to the error message above, there is something missing procedures, I can hardly give precise troubleshooting, it's recommended to follow the steps, and have a try again.  Make sure you have prerequisites required to complete that tutorial.

    At the same time it's also recommended to get help from Windows Azure forum, more Azure experts can help you there.

    Best regards

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Angie Xu Wednesday, January 15, 2014 6:52 AM
    Monday, January 6, 2014 7:45 AM
  • I'm facing the same issue, although for a desktop client instead of a HTML client. I've been trying to figure this one out for a few days now, but I'm pretty sure it's a Lightswitch issue.

    I've setup my Lightswitch application to use Windows authentication. I published the app as Web to an Azure website. On Azure I setup authentication for the website. When I navigate to the website, I get redirected to the Azure login page. I login and return to the application where I'm faced with the NullReferenceException.

    I did some digging in the Lightswitch assemblies using JustDecompile. In the Microsoft.LightSwitch.Utilities.Server.Internal.dll assembly the ToIWindowsIdentity extension method is defined. This method assumes a Windows identity, however, Azure AD returns a ClaimsIdentity. The result is that null is returned, causing the next line of code to throw an error.

    Please advise how to resolve this.

    Sunday, February 8, 2015 1:58 PM
  • Hi S.Schutten,

    Did you manage to resolve the issue. I'm having a similar problem.

    Thanks

    Monday, August 3, 2015 9:43 AM
  • Hi, Have you had any luck as i'm having a similar issue

    thanks

    Tul


    Tul Golan

    Wednesday, September 16, 2015 3:42 PM
  • Sorry, but I gave up on Lightswitch a long time ago. In fact, it was a project for learning, but have found so many problems that was not worth it to invest more time in it. Better focus on MVC...
    Wednesday, September 16, 2015 3:55 PM
  • Farlop, I disagree with you! If LightSwitch is used the way it's intended to, it's 10 times more productive than MVC.

    As far as this problem, I do not think that it's a supported configuration for LightSwitch as I am not sure that Azure AD supports a NTLM Challenge ... hence the Azure Login using a Form. In a local area network, there is a NTLM challenge that provides the credentials if logged in to the local AD OR the browser pops up a modal dialog that asks for your credentials (Username/Domain/Password). 

    In this this request , they explain that they are looking at adding 'legacy' protocols to Azure AD.


    • Proposed as answer by Ian E Wednesday, September 16, 2015 4:23 PM
    • Edited by Ian E Wednesday, September 16, 2015 4:24 PM
    Wednesday, September 16, 2015 4:20 PM
  • Hello Gollem,

    when you use an generic Handler you can get the mailadress aof the Azure AD user with this Code:

        Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    
            Using serverContext As ServerApplicationContext = ServerApplicationContext.CreateContext()
                Dim erg As String = ""
    
                Try
    
                    context.Response.ContentType = "text/plain"
                    context.Response.Write( context.Profile.UserName)
                Catch ex As Exception
                    context.Response.Write(ex.Message)
                End Try
    
            End Using

    Unfortunately I have only a solution for this ask. When you use the create or the modified feature in the middle Tier you get the next Errors.

    But hope this helps.

    Kind Regards

    Thomas

    Sunday, October 18, 2015 5:24 PM