使用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,还尝试向.ascx中的LinkButton添加OnClientClick事件,但是由于它是用户控件而不是页面,因此也无法使用。有什么建议吗?
我认为您将无法从Kentico全局系统事件(例如SecurityEvents.Authenticate.Execute)注册客户端脚本,因为您将无权访问ASP.NET页面。在页面的生命周期内可能不会触发系统事件。
如何创建可从客户端代码调用以查看用户是否成功通过身份验证的WebMethod?
麦克