locked
Allow anonymous access to ServerApplicationContext with forms authentication on RRS feed

  • Question

  • We have a LightSwitch application with HTML client and forms based authentication turned on.

    We have additional directories on the server where publically available websites are stored. We allowed access in the web.comfig using

      <location path="API">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>


    Sites in that directory need to access the server context and data objects. The code there looks like this:

    using (var serverContext = ServerApplicationContext.CreateContext())
    {
      EntitySet<MyObject> set = serverContext.DataWorkspace.ApplicationData.MyObjectSet;
      MyObject obj = set.GetQuery().Execute().FirstOrDefault();
    
      // ...
    }

    Since we allow anonymous access to this page, theres no authenticated user. The call to CreateContext() fails with

    Unable to authenticate.  Access is denied.

    Here I'm stuck. How can one make it possible to use forms authentication for the HTML client on one side and allow anonymous access to page on the server on the other side? We would need full access to objects with read and write.

    Any help is greatly appreciated!

    Thursday, May 22, 2014 5:41 AM

Answers

  • I was blind, but now I can see...

    It seems as if the LightSwitch team has really thought about every detail - A big complement here!

    If one need anonymous access, one can create the server context this way:

    ServerApplicationContext.CreateContext(Microsoft.LightSwitch.Server.ServerApplicationContextCreationOptions.SkipAuthentication)

    Maybe this will help someone with the same problem.

    Thursday, May 22, 2014 6:48 AM

All replies

  • I was blind, but now I can see...

    It seems as if the LightSwitch team has really thought about every detail - A big complement here!

    If one need anonymous access, one can create the server context this way:

    ServerApplicationContext.CreateContext(Microsoft.LightSwitch.Server.ServerApplicationContextCreationOptions.SkipAuthentication)

    Maybe this will help someone with the same problem.

    Thursday, May 22, 2014 6:48 AM
  • If one need anonymous access, one can create the server context this way:

    ServerApplicationContext.CreateContext(Microsoft.LightSwitch.Server.ServerApplicationContextCreationOptions.SkipAuthentication)

    Maybe this will help someone with the same problem.

    Glad to hear that you have solved this issue by yourself, and it is very appreciated to share your solution to us. It will be helpful for others, and welcome to post your question on LS forum in the future. :)

    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.

    Friday, May 23, 2014 7:23 AM
  • Hi,

    I'm not sure I can implement your asnwer in my case. I want to mix Anonymous and authenticated users within the same LS app i.e some pages of the app are for authenticated users only. Is this feasible?

    Tks.

    François

    Tuesday, June 17, 2014 8:33 AM