简体   繁体   English

YAF-从主页验证用户

[英]YAF - Authenticate user from main page

Specs: 眼镜:

What's happening? 发生了什么?

I have a site: http://www.mysite.com and at that site I have set up YAF and when a user visits http://www.mysite.com/forum they are taken to the forum. 我有一个网站: http : //www.mysite.com ,在该网站上我建立了YAF,当用户访问http://www.mysite.com/forum时,他们将被带到论坛。

What do I want? 我想要什么?

When a user logs into my site, I want to create a cookie for them so that when the user visits http://www.mysite.com/forum they are automatically logged into the forum. 当用户登录到我的网站时,我想为他们创建一个cookie,以便当用户访问http://www.mysite.com/forum时,他们将自动登录到论坛。

What have I done? 我做了什么?

When the user registers on my site a YAF account is created for them (working fine). 当用户在我的网站上注册时,将为他们创建一个YAF帐户(工作正常)。 When the user logs into my site, I authenticate them and create a cookie but I also want to create a cookie for the forum so that the user does not have to log into the forum separately. 当用户登录到我的站点时,我对它们进行身份验证并创建一个cookie,但我也想为该论坛创建一个cookie,以便用户不必分别登录该论坛。

To create the cookie for the user I am doing this (so that YAF detects them as logged in): 要为用户创建Cookie,我需要这样做(以便YAF将其检测为已登录):

    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(30), true, "");
    var encryptedTicket = CookieHelper.EncryptTicket(ticket);
    var cookie = CookieHelper.CreateCookie(encryptedTicket, ".YAFNET_Authentication");
    cookie.Path = "/";
    cookie.HttpOnly = true;
    CookieHelper.AddCookie(cookie);

I am expecting to now be authenticated when I visit http://www.mysite.com/forum 我希望现在可以在访问http://www.mysite.com/forum时通过身份验证

Anybody have any words of wisdom? 有人有智慧的话吗?

--Rich - 丰富

Nevermind... 没关系...

Here is the solution: 解决方法如下:

Added a section to both web.config's with the same values. 为两个web.config添加了一个具有相同值的部分。 This allows the main website to create an encrypted session key for the login that the YAF site can decrypt. 这允许主网站为YAF站点可以解密的登录创建加密的会话密钥。 Put this within the section. 将其放在本节中。 Change the keys to a random 48-hex-character value of your own (I used RoboForm to generate my keys). 将密钥更改为您自己的随机48进制字符值(我使用RoboForm生成了密钥)。

<machineKey validationKey="DBAEF98E532D4161826F8351C794DFD27C0F814262FD6986"
decryptionKey="DBAEF98E532D4161826F8351C794DFD27C0F814262FD6986"
validation="SHA1" decryption="AES" />

Answer found here: Log in YAF user 在这里找到答案: 登录YAF用户

Hope it helps someone else one day. 希望有一天能对别人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM