MVC 5 App with Google OAuth2 Sign-on issues - asp.net

I am following this article to login using a google account. However even after installing the latest version of entity framework to the the project and also the latest versions of Microsoft.AspNet.Identity.Core and Microsoft.AspNet.Identity.Owin, I am still getting an error at these lines
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
The first error is that my ApplicationDbContext does not contain a definition for Create. Now how is this possible? Or is this something I have to implement myself in the ApplicationDbContext class? If yes, wont those changes be lost when I reacreate the edmx file?
The second problem is there is no ApplicationUserManager class present. What will have to be the definition of this class?
Am I missing some references or something?
Thanks.

You don't need those lines in your code, that article is using an old version of the template. All you need to do is copy the Google AppId and it should work

Related

IdentityServer4.Services.InMemory not working

I google a lot but not find any solution. Below is my problem :
I make a simple project where I use reference "IdentityServer4.Postgresql": "1.0.0"
where "using IdentityServer4.Services.InMemory" works perfectly.
But when I use "IdentityServer4.Postgresql": "2.0.0" then IdentityServer4.Services.InMemory always shows error.
That means version 2 of IdentityServer4.Postgresql not support IdentityServer4.Services.InMemory.
How can I use IdentityServer4.Services.InMemory for "IdentityServer4.Postgresql": "2.0.0"?
Thanks in advance.
IdentityServer4.Postgresql is not a part of the IdentityServer project, but sounds like a community contribution. You may have a better result by contacting the library creator.
Otherwise, you could try the official IdentityServer4.EntityFramework package that is maintained by the IdentityServer team in combination with an Entity Framework Core database provider for PostgreSQL.
The official quickstarts only show adding Entity Framework in the 8th quickstart. You'll have to do each one in succession up to the eighth one to fully understand / make sure to have the code you need.
After you have Entity Framework added to the configuration, you can support a Postgres database by just adding dependencies.

BrockAllen Identity Reboot - no longer functions on ASP.NET MVC 5

Current project:
ASP.NET 4.5.2
MVC 5
EF 6
So I have come across a bit of a wrinkle. I have been using the BrockAllen Identity Reboot (BAER) to make my MVC 5 projects just that much more secure. Unfortunately, BAER appears to have stopped working. Even on a clean MVC 5 setup, with zero additional customization, adding all the required content paints the ITwoFactorCode in IdentityModels.cs:
public class ApplicationUser : IdentityUser, ITwoFactorCode {
with:
'ApplicationUser' does not implement interface member 'ITwoFactorCode<string>.HashedTwoFactorAuthCode'
'ApplicationUser' does not implement interface member 'ITwoFactorCode<string>.DateTwoFactorAuthCodeIssued'
I have confirmed that this occurs on even a newly set up project with zero additional customizations. Apparently something has changed in DotNet in the last six months to render this NuGet package inoperative. I first ran into this issue when I tried to create a hybrid MVC/API project, but it affects pure MVC projects even as the first package added.
Suggestions? I have already tried to contact BrockAllen and have come up with zero responses finally managed to contact him via eMail. I have opened an issue on GitHub.

WCF Update Service Reference fails

When trying to update service reference I get following error -
I read guide-line at many places that we should checkin only Reference.cs. But I have checked in other ServiceReference files, (like wsdl, xsd etc) as well.
Can this be a cause of UpdateService Reference to failure?
Sounds like you are targeting the wrong framework in your project or you need to completely delete the service reference and re-add it instead of trying to update.
Check this link out
http://connect.microsoft.com/VisualStudio/feedback/details/542789/could-not-resolve-mscorlib-for-target-framework-netframework-version-v4-0-this-can-happen-if-the-target-framework-is-not-installed-or-if-the-framework-moniker-is-incorrectly-formatted
Good Luck

MVC2 with Ninject.Web.Mvc 2.2 and Ninject 2.2 runtime version 4.0 always asks for parameterless constructor for controllers

I have a previous project running Ninject 2.0 runtime version 2.0 and now I am using Ninject in a new project and using the new Ninject, ninject web.mvc version 2.2 for runtime version 4.0.
Every single time I get the error no parameterless constructor
Invalid Operation exception
An error occurred when trying to create a controller of type HomeController'. Make sure that the controller has a parameterless public constructor.
What am I missing. All the bindings are registered.
Do I need to now define interfaces for Controllers as well such as HomeController as IHomeController as I have seen in some examples, Or do I get back to using the older version
There is one version that does not show activation exceptions properly but show this exception instead. Most likely the problem is a duplicated binding.
In addition to what Remo Gloor said, you might want to check that MVC is set up to use Ninject correctly. I was doing some things manually on an older version of the MVC plugin and ended up needing to just bite the bullet and make Global extend the NinjectHttpApplication class, which I had previously been avoiding.
The error you're getting is the error you would get if MVC tries using its built-in controller factory to produce controllers. So you may want to create a custom method binding on your controller class and put a breakpoint inside to make sure it's even being invoked.
You may also want to switch to version 2.3. You can pick up the latest builds of Ninject and all its extensions here.
I have seen this issue mentioned couple of times on forums where there is no direct answer, here is the solution to the above problem, i.e., working with latest ninject
Download the latest Ninject from github.
The ninject I got for MVC2 is named as Ninject.Web.Mvc2-2.2.0.0-release-net-4.0 (runtime version 4)
Now during adding reference add Ninject.Web.Mvc.dll(check the version is same as above by right click properties in VS)
Now Add Ninject.dll from the lib folder in same parent folder (check the version as above)
Now Add CommonServiceLocator.NinjectAdapter.dll from the extensions folder in lib parent folder (check the version as above.)
The missing link in all these have been the commonserviceLocator.dll and the correct version should match. This should be tried if you are sure your bindings are correct as mine were and check to see if your project work with older version.
Thanks to everyone, and good luck :)

Ninject with MVC3 RTM

I've upgraded MVC3 from RC2 to RTM. We were using Ninject 2.1.0.76, but things stopped working once I upgraded. So I used the NuGet manager to get the latest Ninject, Ninject.MVC3 and Ninject.Web.Mvc libraries (2.1.0.91, 1.0.0.0 and 2.1.0.39 respectively). Now, it creates an AppStart_NinjectMVC3 file.
I removed NinjectHttpApplication from my global.asax and made it back into a regular HttpApplication. When I tried to build, I get;
"Exception has been thrown by the target of an invocation"
Looking further, if I disable the following line;
DependencyResolver.SetResolver(new NinjectServiceLocator(kernel));
The build goes through. But I'm pretty sure I don't want to do this.
Any ideas?
----- UPDATE ---------
I created a new MVC3 project, added the reference to Ninject.MVC3 and this builds and runs fine. I compared web.config, don't see any differences that relate to Ninject or MVC in the two. A fresh project doesn't add the Ninject.Web.Mvc library, so I removed it and commented out all code relating to that, and still, the error occurs.
Since ASP.NET MVC 3 Beta the IServiceLocator interface is replaced by IDependencyResolver. I'm not sure Ninject.MVC3 already has a release where they have implemented this interface.
Judging from the line DependencyResolver.SetResolver(new NinjectServiceLocator(kernel)) it appears they have not.
Here's a simple implementation of this interface for Ninject.
UPDATE: The Ninject.Web.Mvc library has a NinjectDependencyResolver class that extends from the IDependencyResolver interface. I think you should use this one (I do and everything works fine).
Download the dlls from here
https://github.com/ninject/ninject/archives/master
https://github.com/ninject/ninject.web.mvc/archives/master
Further more do not use Ninject.MVC3 all you need ist Ninject.Web.Mvc
I also have an article documenting same here

Resources