Welcome Guest! To enable all features please Login or Register.
Options
View
Go to last post Go to first unread
Offline rich2020  
#1 Posted : Friday, January 23, 2015 8:42:26 AM(UTC)
rich2020


Rank: YAF Camper

Reputation:

Joined: 6/22/2014(UTC)
Posts: 12

Thanks: 1 times
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"Wink;
valueCollection.Add("applicationName", "YetAnotherForum"Wink;
valueCollection.Add("passwordFormat", "Clear"Wink;
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("../"Wink;
}

Thanks!
Sponsor
Offline bbobb  
#2 Posted : Friday, January 23, 2015 6:30:36 PM(UTC)
bbobb


Rank: YAF Developer

Reputation:

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: 10/21/2008(UTC)
Posts: 1,558
Man
Russian Federation
Location: Moscow

Thanks: 51 times
Was thanked: 288 time(s) in 254 post(s)
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);
}


Offline rich2020  
#3 Posted : Saturday, January 24, 2015 2:56:05 PM(UTC)
rich2020


Rank: YAF Camper

Reputation:

Joined: 6/22/2014(UTC)
Posts: 12

Thanks: 1 times
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.

You see, when I log into the main site, I get a cookie with the path "/" (eg: www.mysite.come"Wink. 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 :D
Offline rich2020  
#4 Posted : Saturday, January 24, 2015 3:09:06 PM(UTC)
rich2020


Rank: YAF Camper

Reputation:

Joined: 6/22/2014(UTC)
Posts: 12

Thanks: 1 times
Nevermind! I fixed it! I had forgotten uncomment the machineKey in the YAF web.config!

Smile
Offline Giao duc Tuyen Sinh  
#5 Posted : Friday, November 4, 2016 11:50:21 PM(UTC)
Giao duc Tuyen Sinh


Rank: YAF Forumling

Reputation:

Joined: 11/4/2016(UTC)
Posts: 1
Man

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.
Rss Feed  Atom Feed
Users browsing this topic
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.

Notification

Icon
Error