You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET应用切换FusionAuth登录:按钮需点击两次才跳转的问题

问题:FusionAuth登录需点击两次LinkButton才会跳转
  • 网站原采用会员驱动登录,现切换为FusionAuth登录,已完成客户数据集适配验证并接入认证中间件。
  • 主登录界面中,用户选择数据集后,系统会检索验证对应配置(获取应用及租户ID),并用<asp:LinkButton>替换原登录按钮(隐藏旧用户名/密码字段)。
  • 当前问题:点击LinkButton两次才会重定向到FusionAuth端点,第一次点击仅刷新页面,重新填写数据库信息后第二次可正常跳转。即使将LinkButton移到UpdatePanel外,问题依旧存在。

点击事件处理代码

public void FusionAuthLogin(object sender, EventArgs e) 
{
     // 获取客户编号
     string custNumber = TextboxCustomer.Text.Trim();

     // 获取客户数据库
     string custDatabase = "Starter_Database";

     if (ddlDatabase.SelectedIndex != -1) 
     {
         custDatabase = ddlDatabase.SelectedItem.Value.Trim();
     }

     // 获取匹配的FusionAuth应用ClientId
     string fusionAuthClientId = ConfigurationManager.AppSettings["ClientId:" + custDatabase];

     // 将客户编号和数据库添加为认证请求的state参数
     var authProps = new AuthenticationProperties();
     authProps.Dictionary.Add(FusionAuthMiddlewareHelper.CustomerNumberStateName, custNumber);
     authProps.Dictionary.Add(FusionAuthMiddlewareHelper.CustomerDatabaseStateName, custDatabase);

     // 发起FusionAuth认证挑战
     HttpContext.Current.GetOwinContext().Authentication.Challenge(authProps, FusionAuthMiddlewareHelper.AuthenticationType + "_" + fusionAuthClientId);

     // 理论上上述认证挑战会直接重定向到FusionAuth,若未执行可显示错误信息
     return;
}

前端UpdatePanel配置代码

<asp:UpdatePanel>
    <ContentTemplate>
        <asp:Panel>
            <table>
                ...
                <tr>
                    <td>
                        <asp:LinkButton ID="linkButtonFusionAuthLogin" runat="server" 
                             CausesValidation="false" Height="100%" CssClass="Button"  
                             OnClick="FusionAuthLogin" type ="button" >&nbsp;&nbsp;Log In&nbsp;&nbsp;</asp:LinkButton> 
                    </td>
                </tr>
                ....
            </table>
        </asp:Panel>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID ="linkButtonFusionAuthLogin" />
    </Triggers>
</asp:UpdatePanel>

注:已设置断点验证,两次点击都会执行后台代码,但第一次无跳转行为。

内容的提问来源于stack exchange,提问作者Mark Fall

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 21:25:16