Auto logging in to another ASP.NET Application fro

2019-04-12 06:37发布

问题:

I'm running the latest version of YetAnotherForum in a folder beneath my main WebApplication. The subfolder is configured as an application in IIS and navigating to the folder and logging in works wonderfully. YAF is setup with a membership provider and uses Forms Authentication.

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. It doesn't use any of the built in ASP.NET authentication or membership components.

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.

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. Then, on the processing page I'm calling FormsAuthentication.SetAuthCookie(username, true), then redirecting. But YAF kicks me back to the login page anyway. Not sure where to go from here.

Main site is: example.com/

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)

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

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

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

回答1:

I'd been searching Google for 2 days trying to sort this out, but I finally stumbled onto the solution. I needed a MachineKey that matched on both web.config files for the encryption process.

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

Sweet!