Automatically logging into another ASP.NET application from the main web application

I am running the latest version of YetAnotherForum in a folder under my main WebApplication. The subfolder is configured as an application in IIS and moves to the folder, and the login works wonderfully. YAF installs with a membership provider and uses forms authentication.

What I'm trying to do now is an automatic user login to the forum from the main site. The main website uses user authentication through sessions and cookies. It does not use any built-in authentication components or ASP.NET memberships.

So basically what I want is that when the user clicks on the link to access the forums, they are sent to the processing page, which authenticates them in the YAF application before sending them to a subfolder.

Despite the fact that the main application does not use the built-in authentication parts, I still set the forms to authentication mode and made sure that the tag is lower than those specified in the YAF web.config. Then on the processing page, I call FormsAuthentication.SetAuthCookie (username, true) and then redirects. But YAF still pushes me to the login page. Not sure where to go from here.

Main site: example.com/

web.config:

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

YAF: example.com/yaf (Separate WebApplication Function in IIS)

web.config

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

Processing page: (in pseudo) example.com/autoLogin.aspx.cs

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

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

Source: https://habr.com/ru/post/1731028/


All Articles