从主 Web 应用程序自动登录到另一个 ASP.NET 应用程序

2024-03-21

我正在主 Web 应用程序下的文件夹中运行 YetAnotherForum 的最新版本。该子文件夹在 IIS 中配置为应用程序,导航到该文件夹​​并登录效果非常好。 YAF 通过会员提供商进行设置并使用表单身份验证。

我现在想做的是从主网站自动将用户登录到论坛。主网站通过会话和 cookie 使用自定义身份验证。它不使用任何内置的 ASP.NET 身份验证或成员资格组件。

所以基本上我想要发生的是,当用户单击链接访问论坛时,他们会被发送到一个处理页面,该页面在将它们发送到子文件夹之前对 YAF 应用程序进行身份验证。

尽管主应用程序不使用内置的身份验证部分,但我仍然将身份验证模式设置为表单,并确保其下方的标签与 YAF web.config 中的标签匹配。然后,在处理页面上,我调用 FormsAuthentication.SetAuthCookie(username, true),然后重定向。但 YAF 无论如何还是把我踢回到登录页面。不知道从这里去哪里。

主要站点是: example.com/

网络配置:

<authentication mode="Forms">
  <forms name=".YAFNET_Authentication" protection="All" timeout="43200" cookieless="UseCookies" />
</authentication>

YAF 是: example.com/yaf(IIS 中的单独 Web 应用程序)

网络配置

<authentication mode="Forms">
  <forms name=".YAFNET_Authentication" protection="All" timeout="43200" cookieless="UseCookies" />
</authentication>

处理页面是:(伪) example.com/autoLogin.aspx.cs

public void AutLogin(){
    string userName = doStuffToGetUsername();
    YAFStuff.CreateUserIfNeeeded(userName);

    FormsAuthentication.SetAuthCookie(userName, true);
    Response.Redirect("/yaf/");
}

我在谷歌上搜索了两天试图解决这个问题,但我终于偶然发现了解决方案。我需要一个与两个 web.config 文件相匹配的 MachineKey 来进行加密过程。

http://forum.yetanotherforum.net/yaf_postst8780_Custom-membership-and-role-provider-with-YAF-Profile-provider.aspx http://forum.yetanotherforum.net/yaf_postst8780_Custom-membership-and-role-provider-with-YAF-Profile-provider.aspx

Sweet!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从主 Web 应用程序自动登录到另一个 ASP.NET 应用程序 的相关文章

随机推荐