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

蹲街弑〆低调 提交于 2019-12-21 20:43:19

问题


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!



来源:https://stackoverflow.com/questions/2185228/auto-logging-in-to-another-asp-net-application-from-main-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!