0

In trying to implement authentication in CKFinder by following this "howto", I've written the following file, saved to my CKFinder directory:

<%@page codepage="65001" language="C#" lcid="6153"%>
<%
using CKSource.CKFinder.Connector.Core;
using CKSource.CKFinder.Connector.Core.Authentication;
public class MyAuthenticator:IAuthenticator{
    public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){
        return Task.FromResult((IUser)new User(true,"editor"));
    }
}
%>

However, when I try to load it, I get the a compiler error (CS1513) on the line containing the second using statement stating that a closing bracket (}) is expected, despite the fact that there is no opening bracket ({) anywhere in the file before that line.

Given that I have next to no knowledge of ASP.NET, can someone shed some light on what's happening here and how I would go about solving it?

I have, despite knowing it wouldn't work, tried adding a } to the end of that line to see what would happen and it throws a different compiler error - "CS1518: Expected class, delegate, enum, interface, or struct" - in a completely different file "App_Web_auth.aspx.*.*.0.cs" (the asterisks being random strings of characters on each reload) which, strangely, is nested a few directories down in my %WINDIR%. That error occurs on line 214, which is the second line in the following extract:

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
protected override void FrameworkInitialize() {
    base.FrameworkInitialize();
    this.@__BuildControlTree(this);
    this.AddWrappedFileDependencies(global::ASP.auth_aspx.@__fileDependencies);
    this.Request.ValidateInput();
}

UPDATE 1

If I remove the public class completely, I get yet another compiler error - "CS1003: Syntax error, '(' expected" - this time on the line containing the first using statement. Trial and error led me to figure out that the using statements need to be enclosed in parnetheses but, after adding the public class back in, I still get the original error about the missing }.

<%@page codepage="65001" language="C#" lcid="6153"%>
<%
using(CKSource.CKFinder.Connector.Core);
using(CKSource.CKFinder.Connector.Core.Authentication);
public class MyAuthenticator:IAuthenticator{
    public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){
        return Task.FromResult((IUser)new User(true,"editor"));
    }
}
%>

Removing the class again leads to another new error - "CS0119: 'CKSource.CKFinder.Connector.Core' is a 'namespace', which is not valid in the given context"

UPDATE 2

Per SeM's suggestion, I added the following to the system.web section of CKF's "Web.config" file:

<pages>
    <namespaces>
        <add namespace="CKSource.CKFinder.Connector.Core" />
        <add namespace="CKSource.CKFinder.Connector.Core.Authentication" />
    </namespaces>
</pages>

And updated the contents of my file to be:

<%@page codepage="65001" language="C#" lcid="6153"%>
<%@import namespace="ConnectorBuilder.SetAuthenticator"%>
<%
public class MyAuthenticator:IAuthenticator{
    public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){
        return Task.FromResult((IUser)new User(true,"editor"));
    }
}
%>

This, however, leads to the original error ("CS1513: } expected") now being thrown on line 214 (first line in below extract) of that mystery file in my %WINDIR% - with the added weirdness of the contents of that file having somehow changed.

private void @__Render__control1(System.Web.UI.HtmlTextWriter @__w, System.Web.UI.Control parameterContainer) {

    #line 3 "x:\redacted\path\to\myfile.aspx"

public class MyAuthenticator:IAuthenticator{
    public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){
        return Task.FromResult((IUser)new User(true,"editor"));
    }
}


    #line default
    #line hidden
}

UPDATE 3

Changing my file to use a script tag:

<%@page codepage="65001" language="c#" lcid="6153"%>
<%@import namespace="ConnectorBuilder.SetAuthenticator"%>
<script language="c#" runat="server">
    public class MyAuthenticator:IAuthenticator{
        public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){
            return Task.FromResult((IUser)new User(true,"editor"));
        }
    }
</script>

Leads to a brand new error on line 2: "CS0246: The type or namespace name 'ConnectorBuilder' could not be found (are you missing a using directive or an assembly reference?)"

UPDATE 4

I removed the import directive and received the following error on the line declaring the public task: "CS0246: The type or namespace name 'CancellationToken' could not be found (are you missing a using directive or an assembly reference?)".

Community
  • 1
  • 1
Shaggy
  • 6,696
  • 2
  • 25
  • 45
  • Your second code snippet is missing a closing `}`. – ChrisF May 24 '16 at 10:22
  • That's simply the 4 line extract provided with the error message, @ChrisF. But I opened that file to double check and the `}` is present. I'll update momentarily to include it, to avoid more confusion there, thanks. – Shaggy May 24 '16 at 10:26
  • May be you should try this: add namespaces into your web config then use `<%@ Import namespace="MyProgram.MyNamespace" %>` in your aspx page? [see this example](http://stackoverflow.com/questions/1697169/is-it-possible-to-use-the-using-statement-in-my-aspx-views-asp-net-mvc) – SᴇM May 24 '16 at 10:28
  • I tried adding that line, @SeM, no change. I even tried changing `MyProgram.MyNamespace` to `ConnectorBuilder.SetAuthenticator` with the same result. – Shaggy May 24 '16 at 10:35
  • @Shaggy of course you should change the `MyProgram.MyNamespace`. – SᴇM May 24 '16 at 10:38
  • @Shaggy what if you will delete `<%@import namespace="ConnectorBuilder.SetAuthenticator"%>` line. Sorry i'm not able to test the code, so I'll try it later, if the problem will not be solved. – SᴇM May 24 '16 at 11:22
  • @SeM, removing it led to another error, detailed in update 4 above. – Shaggy May 24 '16 at 11:26
  • @Shaggy what is the namespace of `CancellationToken`? – SᴇM May 24 '16 at 11:36
  • Where would I find that information, @SeM? As I mentioned in my question, I have almost no knowledge of ASP.NET. – Shaggy May 24 '16 at 11:37

2 Answers2

1

Try this:

aspx

<%@page codepage="65001" language="C#" lcid="6153"%>
<%@ Import namespace="YourProgram.YourNamespace" %>
<%
public class MyAuthenticator:IAuthenticator{
    public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){
        return Task.FromResult((IUser)new User(true,"editor"));
    }
}
%>

web.config

<system.web>    
<pages>
   <namespaces>
      <add namespace="CKSource.CKFinder.Connector.Core" />
      <add namespace="CKSource.CKFinder.Connector.Core.Authentication" />
   </namespaces>
</pages>

Update:

please try this on you aspx page:

<%@page codepage="65001" language="C#" lcid="6153"%>
<%@ Import namespace="ConnectorBuilder.SetAuthenticator" %>
<script language="c#" runat="server">
    public class MyAuthenticator:IAuthenticator
    {
        public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken)
        {
            return Task.FromResult((IUser)new User(true,"editor"));
        }
    }
</script>
SᴇM
  • 7,024
  • 3
  • 24
  • 41
  • @Shaggy Can you please provide details about this error? (please update it on your question to make it readable) – SᴇM May 24 '16 at 10:49
  • Thanks for your continued efforts, @SeM but still no joy - see update 3 in my question. I'm beginning to suspect that either the documentation is incomplete or it assumes a knowledge of ASP.NET that is beyond reasonable. – Shaggy May 24 '16 at 11:20
  • Upvoted and accepted for setting me on the right path of using `import` instead of `using`. – Shaggy May 25 '16 at 14:17
  • I'm glad, that I've helped you somehow. – SᴇM May 25 '16 at 19:51
0

After a ridiculous amount of trial & error, I managed to get the problem sorted but I still don't know what the cause or the fix was or why this code works but the code provided in the documentation doesn't. One thing I did manage to figure out is that three of the using statements from the documentation that I'd dismissed as irrelevant to my use case were actually relevant. My file now looks like this:

<%@page codepage="65001" debug="true" lcid="6153"%>
<%@import namespace="System.Linq"%>
<%@import namespace="System.Threading"%>
<%@import namespace="System.Threading.Tasks"%>
<%@import namespace="CKSource.CKFinder.Connector.Core"%>
<%@import namespace="CKSource.CKFinder.Connector.Core.Authentication"%>
<script language="c#" runat="server">
public class MyAuthenticator:IAuthenticator{
    public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest,CancellationToken cancellationToken){
        return Task.FromResult((IUser)new User(true,"editor"));
    }
}
</script>

It's still throwing an error related to the "editor" string being passed to the User function but that is unrelated to the question posed here.

Shaggy
  • 6,696
  • 2
  • 25
  • 45