@@ -674,79 +674,53 @@ internal void Initialize(InterceptArgs e)
674674
675675 private void SetContext ( DataPortalContext context )
676676 {
677+ // set the logical execution location
677678 _oldLocation = Csla . ApplicationContext . LogicalExecutionLocation ;
678679 ApplicationContext . SetLogicalExecutionLocation ( ApplicationContext . LogicalExecutionLocations . Server ) ;
679680
680- if ( ! context . IsRemotePortal && ApplicationContext . WebContextManager != null && ! ApplicationContext . WebContextManager . IsValid )
681+ if ( context . IsRemotePortal )
681682 {
682- // local data portal and no valid HttpContext
683- // if context already exists, then use existing context (from AsyncLocal or TLS)
684- if ( ApplicationContext . ClientContext == null || ApplicationContext . ClientContext . Count == 0 )
685- ApplicationContext . SetContext ( context . ClientContext , context . GlobalContext ) ;
683+ // indicate that the code is physically running on the server
684+ ApplicationContext . SetExecutionLocation ( ApplicationContext . ExecutionLocations . Server ) ;
686685 }
687686
688- // if the dataportal is not remote then
689- // do nothing
690- if ( ! context . IsRemotePortal ) return ;
691-
692- // set the context value so everyone knows the
693- // code is running on the server
694- ApplicationContext . SetExecutionLocation ( ApplicationContext . ExecutionLocations . Server ) ;
695-
696- // set the app context to the value we got from the
697- // client
687+ // set the app context to the value we got from the caller
698688 ApplicationContext . SetContext ( context . ClientContext , context . GlobalContext ) ;
699689
700- // set the thread's culture to match the client
701- #if ! PCL46 && ! PCL259 // rely on NuGet bait-and-switch for actual implementation
702- #if NETCORE
703- System . Globalization . CultureInfo . CurrentCulture =
704- new System . Globalization . CultureInfo ( context . ClientCulture ) ;
705- System . Globalization . CultureInfo . CurrentUICulture =
706- new System . Globalization . CultureInfo ( context . ClientUICulture ) ;
707- #elif NETFX_CORE
708- var list = new System . Collections . ObjectModel . ReadOnlyCollection < string > ( new List < string > { context . ClientUICulture } ) ;
709- Windows . ApplicationModel . Resources . Core . ResourceContext . GetForCurrentView ( ) . Languages = list ;
710- list = new System . Collections . ObjectModel . ReadOnlyCollection < string > ( new List < string > { context . ClientCulture } ) ;
711- Windows . ApplicationModel . Resources . Core . ResourceContext . GetForCurrentView ( ) . Languages = list ;
712- #else
713- System . Threading . Thread . CurrentThread . CurrentCulture =
714- new System . Globalization . CultureInfo ( context . ClientCulture ) ;
715- System . Threading . Thread . CurrentThread . CurrentUICulture =
716- new System . Globalization . CultureInfo ( context . ClientUICulture ) ;
717- #endif
718- #endif
690+ // set the thread's culture to match the caller
691+ SetCulture ( context ) ;
692+
693+ // set current user principal
694+ SetPrincipal ( context ) ;
695+ }
719696
697+ private static void SetPrincipal ( DataPortalContext context )
698+ {
720699 if ( ApplicationContext . AuthenticationType == "Windows" )
721700 {
722701 // When using integrated security, Principal must be null
723702 if ( context . Principal != null )
724- {
725- Csla . Security . SecurityException ex =
726- new Csla . Security . SecurityException ( Resources . NoPrincipalAllowedException ) ;
727- //ex.Action = System.Security.Permissions.SecurityAction.Deny;
728- throw ex ;
729- }
730- #if ! ( ANDROID || IOS ) && ! NETFX_CORE
703+ throw new Csla . Security . SecurityException ( Resources . NoPrincipalAllowedException ) ;
731704 // Set .NET to use integrated security
732705 AppDomain . CurrentDomain . SetPrincipalPolicy ( PrincipalPolicy . WindowsPrincipal ) ;
733- #endif
734706 }
735707 else
736708 {
737- // We expect the some Principal object
709+ // We expect some Principal object
738710 if ( context . Principal == null )
739- {
740- Csla . Security . SecurityException ex =
741- new Csla . Security . SecurityException (
742- Resources . BusinessPrincipalException + " Nothing" ) ;
743- //ex.Action = System.Security.Permissions.SecurityAction.Deny;
744- throw ex ;
745- }
711+ throw new Csla . Security . SecurityException ( Resources . BusinessPrincipalException + " Nothing" ) ;
746712 ApplicationContext . User = context . Principal ;
747713 }
748714 }
749715
716+ private static void SetCulture ( DataPortalContext context )
717+ {
718+ System . Threading . Thread . CurrentThread . CurrentCulture =
719+ new System . Globalization . CultureInfo ( context . ClientCulture ) ;
720+ System . Threading . Thread . CurrentThread . CurrentUICulture =
721+ new System . Globalization . CultureInfo ( context . ClientUICulture ) ;
722+ }
723+
750724 private void ClearContext ( DataPortalContext context )
751725 {
752726 ApplicationContext . SetLogicalExecutionLocation ( _oldLocation ) ;
0 commit comments