您可以从自定义 Kentico 全局事件处理程序中执行 javascript 吗?

Can you execute javascript from within a custom Kentico global event handler?

使用 Kentico 版本 10 并尝试从我创建的自定义事件处理程序(身份验证)中调用 javascript。代码是:

public class CustomAuthenticationModule: Module {
    // Module class constructor, the system registers the module under the name "CustomAuthentication"
    public CustomAuthenticationModule(): base("CustomAuthentication") {}

    // Contains initialization code that is executed when the application starts
    protected override void OnInit() {
        base.OnInit();

        // Assigns a handler to the SecurityEvents.Authenticate.Execute event
        // This event occurs when users attempt to sign in on the website
        SecurityEvents.Authenticate.Execute += OnAuthentication;
    }

    private void OnAuthentication(object sender, AuthenticationEventArgs e) {
        // Checks if the user was authenticated by the default system. Only continues if authentication succeeded.
        if (e.User != null) {
            // Run client-side javascript function called UpdateCrisp

            // Testing only
            EventLogProvider.LogInformation("Crisp update on login", "INFORMATION", "Crisp update successful on login");

        }
    }
}

而 javascript 只是一些简单的东西,例如:

function UpdateCrisp() {
    console.log("Contact updated");
}

我尝试使用 RegisterClientScriptBlock 并尝试将 OnClientClick 事件添加到 .ascx 中的 LinkBut​​ton,但因为它是用户控件而不是页面,所以它也不起作用。有什么建议吗?

我认为您无法从 Kentico 全局系统事件注册客户端脚本,例如 SecurityEvents.Authenticate.Execute,因为您将无法访问 ASP.NET 页面.系统事件可能不会在页面的生命周期内触发。

创建一个可以从客户端代码调用以查看用户是否成功通过身份验证的 WebMethod 如何?

麦克