ignition22
  • Posts: 3
  • Joined: 29/06/2009
Hey Guys

I'm currently working on a solution combining a web application with YAF Forums 1.9.3.

Im planning to use the security and login functionality of the YAF forums for both YAF and the original site however i have come across problems trying to get hold of the user from the original site once logged into YAF.

I find that i can use Role providers from my main site without an issue ie

return Roles.IsUserInRole("Administrators");


however when i try to use

MembershipUser user = Membership.GetUser();


It will always throw an object reference exception. I imagine it is because it cannot find a current user. It seems strange to me then that this very command is used in YAF without any problem. Perhaps the main site gets the same instance of the Role Provider but when it access the Membership Provider it gets a different instance ??

Can someone let me know, is this typically how you should go about getting the current user? If i at least know that then i have something to go on however if that is incorrect it would be good to know before going down that road any further.

Any help is greatly appreciated

Cheers
Sponsor
mddubs
  • Posts: 476
  • Joined: 07/08/2008
http://msdn.microsoft.co....membership.getuser.aspx 

I don't usually see that method called without any parameters so I had to check with the above link. It looks like that will return the current user if, of course, you're using the .NET membership framework. So my only guess is you did not setup YAF to use the .net membership schema and that's why that call fails.
UserPostedImage 
www.bunkerhollow.com  | www.careercomputing.com 
When I post fp:mddubs in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Mek 🙂, who stole this off Ederon 🙂 )
jshepler
  • Posts: 189
  • Joined: 09/08/2008
ignition22 wrote:

Can someone let me know, is this typically how you should go about getting the current user?



Yes, it is typically how you should go about getting the current user IF the site uses the asp.net membership framework.

As to why you're getting an exception, it's pretty much impossible to tell without seeing the entire exception including stack trace. In my experience, there are times when the exception will show a line of code as the source of the exception, but is not where the exception is actually coming from. The stack trace, however, never lies.

Also, I believe that GetUser() will return a null if the user is not authenticated (anonymous). The documentation doesn't specify this, but I'm pretty sure this is true based on my experience using it.

not jsheLPer
ignition22
  • Posts: 3
  • Joined: 29/06/2009
oops someone just broke the forums haha

jshepler wrote:


As to why you're getting an exception, it's pretty much impossible to tell without seeing the entire exception including stack trace.



Your on the money there, should have looked at the evidence before thinking to logically about the problem 🙂. The way things are running at the moment the main site and forums each have their own webconfig.

The trace was pointing to YAF.Classes.Config.get_ConnectionString() which led me to discover that it was looking for a connection string named "yafnet" where as i had renamed the connection string in the main site and thought i had also updated all references some time ago.

because GetUser() was being called in the instance from the main site instead of the forum site it was looking for an entry in its own config.

I think because Roles.IsUserInRole might access session variables or something other then the database on every call it wasnt causing the same problem


Cheers guys
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