YAFLogo

AbhishekRShah
13 years ago
Version : YAF-v1.9.5.5-RTW

I have a website with a login module. (I am not using ASP.Net Membership here.)

When a user register with my website, I am creating required records in YAF tables through webservice.

But now I am trying to make a single signup for both my website and for the YAF.

If a user login to the web by using my login page, he should be able to post messages to YAF without login again though the YAF login interface.

Any detailed guidance on this topic?

Thanks in advance.

Sponsor
AbhishekRShah
13 years ago
Can any developer please look into my question and provide me appropriate guidance or links?
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
13 years ago
The easiest way to login the user to yaf is

 FormsAuthentication.SetAuthCookie(userName, true);

But you should check if the user exists before you make the login

YafContext.Current.Get<MembershipProvider>().ValidateUser(userName, Password)
AbhishekRShah
13 years ago
I did the same thing as per your guidance,

But it again takes me to the Forum Login page.

My Custom Login page (Assume that Correct username and Password is entered)

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YafUser;

public partial class Login : System.Web.UI.Page
{
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        YafUser.Register r = new Register();
        bool Check = r.SetUserCookie(TextBox1.Text);
        if (Check == true)
        {
            Response.Redirect("http://www.vhsdemo.com/forumdemo/default.aspx");
        }
    }
}

My Web-service code :

 
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;
using System.Web.Services;
using YAF.Classes.Core;
using YAF.Classes.Utils;

namespace VHS.Forum
{
     public class Register : WebService
    {
        [WebMethod]
        public bool SetUserCookie(string UserName)
        {
            FormsAuthentication.SetAuthCookie(UserName, true);
            return true;
        }
    }
}

Which step I am missing?

AbhishekRShah
13 years ago

        [WebMethod]
        public bool SetUserCookie(string UserName,string Password)
        {
            
            bool Check=YafContext.Current.Get<MembershipProvider>().ValidateUser(UserName, Password);
            if (Check == true)
            {
                FormsAuthentication.SetAuthCookie(UserName, true);
                return true;
            }
            else
                return false;
        }

System.Web.Security.MembershipProvider' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'YAF.Classes.Core.YafServiceExtensions.Get(YAF.Classes.Core.YafContext)'

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
13 years ago
Try

 FormsAuthentication.RedirectFromLoginPage(UserName, true);

Or as written in the Outdated Wiki Page

http://wiki.yetanotherforum.net/Integration%20with%20existing%20Application%20 (Revisited).ashx


if (Request.QueryString["ReturnUrl"] != null)
{
						  FormsAuthentication.RedirectFromLoginPage(UserName, true);
					  }
					  else
					  {
						  FormsAuthentication.SetAuthCookie(UserName, true);
					  }
AbhishekRShah
13 years ago
Exception is thrown


System.Net.WebException was unhandled by user code
  Message=The request failed with the error message:
--
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fforumdemo%2fdefault.aspx">here</a>.</h2>
</body></html>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SetUserCookieResponse xmlns="http://tempuri.org/"><SetUserCookieResult>true</SetUserCookieResult></SetUserCookieResponse></soap:Body></soap:Envelope>
--.
  Source=System.Web.Services
  StackTrace:
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at YafUser.Register.SetUserCookie(String UserName, String Password) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vhsdemo\eaea8c65\2af81a84\App_WebReferences.ijejjmxk.0.cs:line 98
       at Login.Button1_Click(Object sender, EventArgs e) in d:\ashah\petrel\vhsdemo\Login.aspx.cs:line 14
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
13 years ago

Exception is thrown

System.Net.WebException was unhandled by user code
  Message=The request failed with the error message:
--
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fforumdemo%2fdefault.aspx">here</a>.</h2>
</body></html>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SetUserCookieResponse xmlns="http://tempuri.org/"><SetUserCookieResult>true</SetUserCookieResult></SetUserCookieResponse></soap:Body></soap:Envelope>
--.
  Source=System.Web.Services
  StackTrace:
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at YafUser.Register.SetUserCookie(String UserName, String Password) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vhsdemo\eaea8c65\2af81a84\App_WebReferences.ijejjmxk.0.cs:line 98
       at Login.Button1_Click(Object sender, EventArgs e) in d:\ashah\petrel\vhsdemo\Login.aspx.cs:line 14
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

Originally Posted by: AbhishekRShah 

Ah sorry, from a webservice the redirect can not work.

Why did you use a webservice for that? could run the code directly.

AbhishekRShah
13 years ago
I know it must be very silly questions for you. And Thank that you are helping us out.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.WebControls;
using YafUser;


public partial class Login : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SetAuthCookie(TextBox1.Text, true);
        //FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, true);
        Response.Redirect("http://www.vhsdemo.com/forumdemo/default.aspx");
     }
}

As per guidance, experimented both the options.

FormsAuthentication.SetAuthCookie(TextBox1.Text, true);

and

FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, true);

But both are taking me to Forum login page,

What next.

AbhishekRShah
13 years ago
FYI, While building my website I get this error (from start)

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

*I have configured YAF as application in IIS

AbhishekRShah
13 years ago
Any luck for my issue?
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
13 years ago

Any luck for my issue?

Originally Posted by: AbhishekRShah 

Currently i have no idea. Maybe the manually registering wasnt correct. You should try if the ValidateUser(user,pass) returns true. If not you should try to register the user via the membership and not manually. I recently write the code for the single sign on feature, i can post the code tomorrow, when iam back at my computer if you need it

AbhishekRShah
13 years ago
I got the step by step answer to my question and I resolved it successfully.

http://forum.yetanotherforum.net/yaf_postst1609_User-Login.aspx 

Thank you Naphong for posting it so nicely.

Also, Thanks a lot to tha_watcha, for all your efforts and help.