rich2020
  • Posts: 12
  • Joined: 22/06/2014
Hi guys,

I have integrated YAF with my site: I can login and register via the YAF membership.

Here is the problem: I login on my main site and then navigate to mysite.com/forums and I am not logged into the forum. Then, when I log into the forum and go back to the main site, I am no longer logged into the main site.

I have this in my main site web.config:
<authentication mode="Forms">
<forms name=".YAFNET_Authentication" protection="All" timeout="43200" cookieless="UseCookies" loginUrl="~/Error/UnAuthorized" />
</authentication>

It seems that when logging into the forum, it overwrites the cookie... This could all be circumvented if when logging into the main site and then going to the forum, the user is already logged into the forum (thus not needing to login again....)

Do any of you know how I can log the user into the forum when they sign in on the main site?

Here is my login code:
[HttpPost]
public ActionResult Login(YAF.Types.Models.User user)
{
var provider = new YafMembershipProvider();
var valueCollection = new NameValueCollection();
valueCollection.Add("connectionStringName", "yafnet");
valueCollection.Add("applicationName", "YetAnotherForum");
valueCollection.Add("passwordFormat", "Clear");
provider.Initialize("YafMembershipProvider", valueCollection);

if (provider.ValidateUser(user.DisplayName, user.Password))
{
const MembershipCreateStatus status = MembershipCreateStatus.Success;
var result = BaseClass.GetRegistrationResult(status);
FormsAuthentication.SetAuthCookie(user.DisplayName, false);
// return new JsonResult { Data = message };
}

return Redirect("../");
}

Thanks!
bbobb
  • Posts: 1558
  • Joined: 21/10/2008
Wow! You somehow are creating an instance. This will not do in the case.
Something like this.
YafMembershipProvider mb = (YafMembershipProvider)System.Web.Security.Membership.Providers["YafMembershipProvider"];
if (mb.ValidateUser(sUserName, sPassword))
{
FormsAuthentication.SetAuthCookie(sUserName, false);
}



rich2020
  • Posts: 12
  • Joined: 22/06/2014
Thanks, that makes my code more efficient, but it doesn't solve my problem :(

I can log into my site via the YAF provider, but when I visit the forums, I am not logged in.

You see, when I log into the main site, I get a cookie with the path "/" (eg: www.mysite.come "). However, when I log into the forums (eg: www.mysite.com/fourms ), I get another cookie with the path "/forums".

How can I have just a single cookie so that I can log into the main site (www.mysite.com) and still be logged into the forums when I go to www.mysite.com/forums? 

Many thanks and greetings to Moscow - my girlfriend is from Moscow 😃
rich2020
  • Posts: 12
  • Joined: 22/06/2014
Nevermind! I fixed it! I had forgotten uncomment the machineKey in the YAF web.config!

:)
Giao duc Tuyen Sinh
  • Posts: 1
  • Joined: 05/11/2016
Thanks, that makes my code more efficient, but it doesn't solve my problem Sad
I can log into my site via the YAF provider, but when I visit the forums, I am not logged in.
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved