简体   繁体   English

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

[英]Auto logging in to another ASP.NET Application from main Web Application

I'm running the latest version of YetAnotherForum in a folder beneath my main WebApplication. 我正在我的主WebApplication下面的文件夹中运行最新版本的YetAnotherForum。 The subfolder is configured as an application in IIS and navigating to the folder and logging in works wonderfully. 子文件夹在IIS中配置为应用程序并导航到该文件夹​​并且登录工作非常好。 YAF is setup with a membership provider and uses Forms Authentication. YAF是使用成员资格提供者设置的,并使用表单身份验证。

What I'm trying to do now is to auto login a user into the forum from the main website. 我现在要做的是从主网站自动登录用户进入论坛。 The main website uses custom authentication through sessions and cookies. 主网站通过会话和cookie使用自定义身份验证。 It doesn't use any of the built in ASP.NET authentication or membership components. 它不使用任何内置的ASP.NET身份验证或成员资格组件。

So basically what I want to happen is that when a user click on a link to access the forums, they're sent to a processing page that authenticates them into the YAF Application before it sends them over to the subfolder. 基本上我想要发生的是,当用户点击链接访问论坛时,他们会被发送到一个处理页面,在将它们发送到子文件夹之前将它们验证到YAF应用程序中。

Even though the main app doesn't use the built in authentications pieces, I've still set the authentication mode to forms and made sure the tag beneath that matches the one in the YAF web.config. 即使主应用程序不使用内置的身份验证部分,我仍然将身份验证模式设置为表单,并确保下面的标记与YAF web.config中的标记匹配。 Then, on the processing page I'm calling FormsAuthentication.SetAuthCookie(username, true), then redirecting. 然后,在处理页面上我调用FormsAuthentication.SetAuthCookie(用户名,true),然后重定向。 But YAF kicks me back to the login page anyway. 但是YAF无论如何都会把我踢回登录页面。 Not sure where to go from here. 不知道从哪里开始。

Main site is: example.com/ 主要网站是:example.com/

web.config: web.config中:

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

YAF is: example.com/yaf (Seperate WebApplication in IIS) YAF是:example.com/yaf(在IIS中分离WebApplication)

web.config web.config中

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

Processing page is: (in pseudo) example.com/autoLogin.aspx.cs 处理页面是:(在伪)example.com/autoLogin.aspx.cs

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

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

I'd been searching Google for 2 days trying to sort this out, but I finally stumbled onto the solution. 我一直在谷歌搜索2天试图解决这个问题,但我最终偶然发现了解决方案。 I needed a MachineKey that matched on both web.config files for the encryption process. 我需要一个与两个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! 甜!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM