YAFLogo

HeadFried
  • HeadFried
  • 55.6% (Neutral)
  • YAF Camper Topic Starter
11 years ago

We have set up the YAF forum and it is working fine, we have this on a subdomain.

forum.oursite.com

We also have a custom made site we've have built using MVC 4.

www.oursite,com

We've added a Content table to the YAF database, our main site is pulling content from this database.

We need to now, secure the content on our main MVC site, users must login to view it.

We want to put a login on our MVC site in order to authenticate the users, once authenticated they will then be able to view our content. We want them to use the YAF_User table.

Is there a tutorial or a sample project I can download to help me out?

Has anyone any ideas?

Sponsor
Jaben
  • Jaben
  • 100% (Exalted)
  • YAF Developer
10 years ago
You need the same machine key on the both sites and both sites need the same authentication cookie. Also, the domain setting for the auth cookie has to be set properly:

<authentication mode="Forms">
      <forms name=".mysite" protection="All" timeout="43200" slidingExpiration="true" cookieless="UseCookies" domain=".yetanotherforum.net" />
    </authentication>
Notice the domain key with the ".yetanotherforum.net" -- that authentication will work for ALL yetanotherforum.net domains... so www.yetanotherforum.net, forum.yetanotherforum.net, wiki.yetanotherforum.net and yetanotherforum.net.

That's the single most important trick to doing single sign on authentication for a whole site. Good luck.

HeadFried
  • HeadFried
  • 55.6% (Neutral)
  • YAF Camper Topic Starter
10 years ago

You need the same machine key on the both sites and both sites need the same authentication cookie. Also, the domain setting for the auth cookie has to be set properly:

<authentication mode="Forms">
      <forms name=".mysite" protection="All" timeout="43200" slidingExpiration="true" cookieless="UseCookies" domain=".yetanotherforum.net" />
    </authentication>
Notice the domain key with the ".yetanotherforum.net" -- that authentication will work for ALL yetanotherforum.net domains... so www.yetanotherforum.net, forum.yetanotherforum.net, wiki.yetanotherforum.net and yetanotherforum.net.

That's the single most important trick to doing single sign on authentication for a whole site. Good luck.

Originally Posted by: Jaben 

Thanks for this, but we're still very stuck.

Does anybody have an example of their account controller for an MVC 4 project were they have managed to authenticate a user from the YAF database?

Jaben
  • Jaben
  • 100% (Exalted)
  • YAF Developer
10 years ago
Which provider are you using? It's not "YAF.NET's database" -- it's called Forms Authentication and YAF is a slave to it. Both MVC and YAF.NET use the same provider. That is the easy part. The hard part is getting single sign on working across sub domains.

Seems your stuck on the abstraction... which seems to be a big problem with understanding Forms Authentication. YAF.NET does not provide the authentication -- ASP.NET does. When you start to think in terms that concept -- it should be easier to understand. The only thing required is that the settings are all the same.

HeadFried
  • HeadFried
  • 55.6% (Neutral)
  • YAF Camper Topic Starter
10 years ago

Which provider are you using? It's not "YAF.NET's database" -- it's called Forms Authentication and YAF is a slave to it. Both MVC and YAF.NET use the same provider. That is the easy part. The hard part is getting single sign on working across sub domains.

Seems your stuck on the abstraction... which seems to be a big problem with understanding Forms Authentication. YAF.NET does not provide the authentication -- ASP.NET does. When you start to think in terms that concept -- it should be easier to understand. The only thing required is that the settings are all the same.

Originally Posted by: Jaben 

Jaben,

Thanks for your help with this.

I've created an ASP.Net web application, updated the web.config to point to the YAF database, ive added references to the YAF dlls, the project loads and I can login...happy days.

I've then created a simple MVC 3 project updated the webConfig etc...ran the project.....and I can login again...happy days.

Now...

I am trying to create an MVC 4 project, and it wont run as MVC 4 does not use the same provider, rafter a bit of googling Ive realised that MVC 4 is using SimpleMemberShipProvider, im not sure if there is a way round this?

What would be great is a sample MVC 4 project that works with the YAF database....or even just the web config file and account controller!

Thanks again for your help with this, we love the forum!

Jaben
  • Jaben
  • 100% (Exalted)
  • YAF Developer
10 years ago
You should still be able to use YAF.NET providers for MVC4 project. Yes, the default is the simple providers... but just replace with YAF.NET providers and ... viola, working login.

... Glad you like the forum ;)

Also, FYI, you don't have to use YAF.NET providers with YAF. You can use any membership provider -- including "SimpleMembershipProvider" or any other provider.

JP
  • JP
  • 100% (Exalted)
  • YAF Leader
10 years ago
I run an MVC4 site with the YAF Membership provider. However, the forum is a losely integrated part of the site on the same site address in a subfolder..

What I have done is to use the same static machine key for both in the web.config.

All logins handled by the YAF login, not using the MVC4 AccountController at all...


He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Old Chinese Proverb]