#1
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!
Topic Starter
  • rich2020
  • Rank: YAF Camper
  • Reputation:
    Neutral
    57.2%
  • Joined: 22/06/2014
  • Posts: 12
  • Thanks: 1 times
#2
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);
}



  • bbobb
  • Rank: YAF Developer
  • Reputation:
    Exalted
    100%
  • Medals:
    Medal of Honor Key: Given to pillars of the community who are key players in the YAF community and project.Medal of Honor for a YAF Database Key Player: Holds the key to YAF database. Bow down!Medal of Honor for the Support King: Given for answering tons of support questions and generally helping the community.Medal of Honor for the Support Knight: Given to a community member who has answered lots of support questions.
  • Joined: 21/10/2008
  • Posts: 1,558
  •  Man  Russian Federation
  • Location: Moscow
  • Thanks: 51 times
  • Was thanked: 287 time(s) in 253 post(s)
#3
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 😃
Topic Starter
  • rich2020
  • Rank: YAF Camper
  • Reputation:
    Neutral
    57.2%
  • Joined: 22/06/2014
  • Posts: 12
  • Thanks: 1 times
#4
Nevermind! I fixed it! I had forgotten uncomment the machineKey in the YAF web.config!

Topic Starter
  • rich2020
  • Rank: YAF Camper
  • Reputation:
    Neutral
    57.2%
  • Joined: 22/06/2014
  • Posts: 12
  • Thanks: 1 times
#5
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.
  • Giao duc Tuyen Sinh
  • Rank: YAF Forumling
  • Reputation:
    Neutral
    50.6%
  • Joined: 05/11/2016
  • Posts: 1
  •  Man 
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