Starcounter/Starcounter.Authorization

Starting an app in non-default database causes exception

Opened this issue · 2 comments

Starcounter.DbException: ScErrFailingEntrypoint (SCERR4259): The user code entrypoint method raised an exception. System.ArgumentException: Handler relative URI: "/useradmin\useradmin/starcounter.authorization.redirection.html" is ill formed. Please consult RFC 3986 for more information.

This is caused by this line. Application.ToString() prepends database name with a backslash, but only if database is not default. The backslash causes the exception, but illegal characters in db name could also cause trouble.

I can confirm the problem still exists:

Starcounter.DbException: ScErrFailingEntrypoint (SCERR4259): The user code entrypoint method raised an exception. System.ArgumentException: Handler relative URI: "/mydatabase\blendingeditor/starcounter.authorization.redirection.html" is ill formed. Please consult RFC 3986 for more information.
   at Starcounter.Rest.UriManagedHandlersCodegen.GenerateParsingDelegateAndGetParameters(String methodSpaceUri, MethodInfo userDelegateInfo, Expression delegExpr, Byte[]& nativeParamTypes, Type& dbObjectType, Type& argMessageType, Type& argSessionType) in C:\ c_work\sc-19997\Level1\src\Starcounter.Rest\UriManagedHandlersCodegen.cs:line 727
   at Starcounter.Rest.UriManagedHandlersCodegen.RegisterDelegate(UInt16 port, String methodSpaceUri, MethodInfo userDelegateInfo, Expression delegExpr, NetworkProtocolType protoType, HandlerOptions ho) in C:\       c_work\sc-19997\Level1\src\Starcounter.Rest\UriManagedHandlersCodegen.cs:line 653
   at Starcounter.Rest.UriManagedHandlersCodegen.GenerateParsingDelegate(UInt16 port, String methodSpaceUri, Func`1 userDelegate, HandlerOptions ho, NetworkProtocolType protoType) in C:\      c_work\sc-19997\Level1\src\Starcounter.Rest\UriManagedHandlersCodegen.cs:line 919
   at Starcounter.Handle.GET(String uriTemplate, Func`1 code, HandlerOptions ho) in C:\ c_work\sc-19997\Level1\src\Starcounter.Internal\Handle.GET.cs:line 115
   at Starcounter.Authorization.Authentication.AuthenticationStartupFilter.RegisterHtmlPage(String uri, String content)
   at Starcounter.Authorization.Authentication.AuthenticationStartupFilter.<>c__DisplayClass6_0.<Configure>b__0(IApplicationBuilder app)
   at Starcounter.Authorization.Settings.EnsureSettingsStartupFilter`1.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Starcounter.Startup.DefaultStarcounterBootstrapper.Start(IStartup application)
   at BlendingEditor.Program.Main(String[] args)
   at Starcounter.Hosting.Package.ExecuteEntryPoint(Application application, Assembly assembly) in C:\  c_work\sc-19997\Level1\src\Starcounter.Hosting\Hosting\Package.cs:line 556
Version: 2.4.990.243.
Help page: https://docs.starcounter.io/?q=SCERR4259.
   at Starcounter.Hosting.Package.ExecuteEntryPoint(Application application, Assembly assembly) in C:\  c_work\sc-19997\Level1\src\Starcounter.Hosting\Hosting\Package.cs:line 566
   at Starcounter.Hosting.Package.ProcessWithinCurrentApplication(Application application, ApplicationDirectory applicationDir) in C:\  c_work\sc-19997\Level1\src\Starcounter.Hosting\Hosting\Package.cs:line 262
   at Starcounter.Hosting.Package.Process() in C:\      c_work\sc-19997\Level1\src\Starcounter.Hosting\Hosting\Package.cs:line 134
   at Starcounter.Hosting.Package.Process(IntPtr hPackage) in C:\       c_work\sc-19997\Level1\src\Starcounter.Hosting\Hosting\Package.cs:line 53
   at StarcounterInternal.Hosting.Processor.RunMessageLoop(Void* hsched) in C:\ c_work\sc-19997\Level1\src\Starcounter.Hosting\StarcounterInternal.Hosting\Processor.cs:line 90
ErrorCode=4259
HResult=-2146233088
HelpLink=https://docs.starcounter.io/?q=SCERR4259
---> System.ArgumentException: Handler relative URI: "/mydatabase\blendingeditor/starcounter.authorization.redirection.html" is ill formed. Please consult RFC 3986 for more information.
   at Starcounter.Rest.UriManagedHandlersCodegen.GenerateParsingDelegateAndGetParameters(String methodSpaceUri, MethodInfo userDelegateInfo, Expression delegExpr, Byte[]& nativeParamTypes, Type& dbObjectType, Type& argMessageType, Type& argSessionType) in C:\ c_work\sc-19997\Level1\src\Starcounter.Rest\UriManagedHandlersCodegen.cs:line 727
   at Starcounter.Rest.UriManagedHandlersCodegen.RegisterDelegate(UInt16 port, String methodSpaceUri, MethodInfo userDelegateInfo, Expression delegExpr, NetworkProtocolType protoType, HandlerOptions ho) in C:\       c_work\sc-19997\Level1\src\Starcounter.Rest\UriManagedHandlersCodegen.cs:line 653
   at Starcounter.Rest.UriManagedHandlersCodegen.GenerateParsingDelegate(UInt16 port, String methodSpaceUri, Func`1 userDelegate, HandlerOptions ho, NetworkProtocolType protoType) in C:\      c_work\sc-19997\Level1\src\Starcounter.Rest\UriManagedHandlersCodegen.cs:line 919
   at Starcounter.Handle.GET(String uriTemplate, Func`1 code, HandlerOptions ho) in C:\ c_work\sc-19997\Level1\src\Starcounter.Internal\Handle.GET.cs:line 115
   at Starcounter.Authorization.Authentication.AuthenticationStartupFilter.RegisterHtmlPage(String uri, String content)
   at Starcounter.Authorization.Authentication.AuthenticationStartupFilter.<>c__DisplayClass6_0.<Configure>b__0(IApplicationBuilder app)
   at Starcounter.Authorization.Settings.EnsureSettingsStartupFilter`1.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Starcounter.Startup.DefaultStarcounterBootstrapper.Start(IStartup application)
   at BlendingEditor.Program.Main(String[] args)
   at Starcounter.Hosting.Package.ExecuteEntryPoint(Application application, Assembly assembly) in C:\  c_work\sc-19997\Level1\src\Starcounter.Hosting\Hosting\Package.cs:line 556
HResult=-2147024809

The fix is trivial. Starcounter.Application has the following structure when started in custom database.

{
  "Host": {},
  "Name": "Playground",
  "DisplayName": "custom\\Playground",
  "FullName": "custom\\Playground",
  "FilePath": "D:\\GitHub\\Miyconst\\Playground\\Playground\\bin\\Debug\\Playground.exe",
  "WorkingDirectory": "D:\\GitHub\\Miyconst\\Playground\\Playground",
  "ResourceDirectories": [],
  "Arguments": null
}

So, this would fix the issue:

-public string RedirectionViewUri => $"/{Application.Current}/Starcounter.Authorization.Redirection.html";
+public string RedirectionViewUri => $"/{Application.Current.Name}/Starcounter.Authorization.Redirection.html";