YAFLogo

Posted by: AbhishekRShah - Monday, 6 June 2011 14:35:35
[size=7]Version : YAF-v1.9.5.5-RTW[/size] 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.

Posted by: AbhishekRShah - Tuesday, 7 June 2011 07:32:27
Can any developer please look into my question and provide me appropriate guidance or links?

Posted by: tha_watcha - Tuesday, 7 June 2011 11:32:51
The easiest way to login the user to yaf is [code=csharp] FormsAuthentication.SetAuthCookie(userName, true);[/code] But you should check if the user exists before you make the login [code=csharp]YafContext.Current.Get().ValidateUser(userName, Password)[/code]

Posted by: AbhishekRShah - Tuesday, 7 June 2011 13:17:41
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) [code=csharp] 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"); } } } [/code] My Web-service code : [code=csharp] 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; } } } [/code] Which step I am missing?

Posted by: AbhishekRShah - Tuesday, 7 June 2011 13:28:07
[code=csharp] [WebMethod] public bool SetUserCookie(string UserName,string Password) { bool Check=YafContext.Current.Get().ValidateUser(UserName, Password); if (Check == true) { FormsAuthentication.SetAuthCookie(UserName, true); return true; } else return false; } [/code] 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)'

Posted by: tha_watcha - Tuesday, 7 June 2011 13:29:35
Try [code=csharp] FormsAuthentication.RedirectFromLoginPage(UserName, true);[/code] Or as written in the Outdated Wiki Page http://wiki.yetanotherforum.net/Integration%20with%20existing%20Application%20(Revisited).ashx [code=csharp] if (Request.QueryString["ReturnUrl"] != null) { FormsAuthentication.RedirectFromLoginPage(UserName, true); } else { FormsAuthentication.SetAuthCookie(UserName, true); } [/code]

Posted by: AbhishekRShah - Tuesday, 7 June 2011 14:03:47
Exception is thrown [code] System.Net.WebException was unhandled by user code Message=The request failed with the error message: -- Object moved

Object moved to here.

true --. 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: [/code]

Posted by: tha_watcha - Tuesday, 7 June 2011 14:19:04
[quote=AbhishekRShah;50084]Exception is thrown [code=plain]System.Net.WebException was unhandled by user code Message=The request failed with the error message: -- Object moved

Object moved to here.

true --. 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:[/code] [/quote] Ah sorry, from a webservice the redirect can not work. Why did you use a webservice for that? could run the code directly.

Posted by: AbhishekRShah - Tuesday, 7 June 2011 14:35:13
I know it must be very silly questions for you. And Thank that you are helping us out. [code=csharp] 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"); } } [/code] 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.

Posted by: AbhishekRShah - Tuesday, 7 June 2011 14:38:04
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

Posted by: AbhishekRShah - Tuesday, 7 June 2011 14:54:38
Any luck for my issue?

Posted by: tha_watcha - Tuesday, 7 June 2011 16:58:47
[quote=AbhishekRShah;50088]Any luck for my issue?[/quote] 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

Posted by: AbhishekRShah - Wednesday, 8 June 2011 15:11:53
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.