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

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.

Related

APIGatewayProxyRequest not getting populated after dotnet core upgrade from 1.0 to 2.1

I am currently working on to upgrade dotnet core framework version from 1.0 to 2.1 of an existing product.
The UI of the same is made in Angular which makes service calls to AWS Lambdas (made using dotnet core) for all the requirements. User data is stored in AWS Cognito and every time a service call is made it first gets verified by fetching data from Cognito. This part stopped working after the framework upgrade.
The following lines of code stopped fetching data:
if (!HttpContext.Items.Keys.Contains("APIGatewayRequest"))
{
//Log error
}
HttpContext.Items["APIGatewayRequest"] as APIGatewayProxyRequest;
Custom api gateway authorizer is used for Cognito and also HttpContext is used inside a controller.
The following image shows the Request.HttpContext structure for me:
Any information around this issue will be great.
Finally, after trying desperately for a couple of days, I got the resolution. In the newer version of DotNet Core the value of the HttpContext key got changed from "APIGatewayRequest" to "LambdaRequestObject" causing all the pain. And the code was using the value directly from a constant declared inside the project and was not using the constant "AbstractAspNetCoreFunction.LAMBDA_REQUEST_OBJECT" provided by the framework.

How to properly update SQL database in Azure after EF Code First model of asp.net mvc model change?

It seems like I always have a variety of problems doing this, and usually I end up nuking the db out of frustration and rebuilding, but obviously there has to be some way to do this.
I have an existing asp.net mvc web app living with its sql db in azure. Works fine has some data that can be replaced but, again, the point is to learn how to update model without destroying the database.
In VS2017 I add one property public string ScreenShot { get; set; }
I make some small changes to my mvc and web api controllers to handle this extra property. I update my localdb via packmanager console and add-migration addprop and update-database. Works fine, run it locally, no probs.
Goto publish, goto settings, check update database. Click publish.
It hangs for like 5 or 6 min and I get:
Warning : A project which specifies SQL Server 2016 as the target platform may experience compatibility issues with Microsoft Azure SQL Database v12. when publishing
I try publishing several times and get the same thing. Google, look around, scratch my head, try again and it seems to publish. Site opens, and somehow I have lost my bootstrap theme. In fact in my Content folder I now have 4 files i believe are new: bootstrap-theme. (css,css.map, min.css, min.css.map) (same prefix , different suffix) as well as what I think are virgin versions of those without theme in the name, and seems to be the default mvc theme of black and white.
When I goto my app and I get an generic error and checking elmah I get:
System.InvalidOperationException: The model backing the 'TaskTrackerContext'
context has changed since the database was created. Consider using Code
First Migrations to update the database (http://go.microsoft.com/fwlink/?
LinkId=238269).
Well I really thought thats what I did. Almost forgot one thing! Maybe this is where my problem lies: I actually had to run two migrations-in addition to the model change I dropped a column that had never been used (scaffolding a controller for a DTO version of one of my models added it to my context which created a table).
I did create a new branch before making any of these change so I could just revert back but at some point I have to make this work and have to understand how to do it without destroying my db and remaking fresh.
A check in SQL object explorer shows it added the ScreenShot column to my table but didn't remove the unused table.
This works for me :
In visual Studio, go to publish settings and then select the option
Execute Code First Migration
Please see the screenshots below
Kind regards

Enity Data source wizard only compatiible with framework 5

I'm going to try and connect to my EF Data Model for the first time and when I do I pull this error message:
This version of the Entity Data Source wizard is only compatible with Entity Framework 5. If you’re not using Entity Framework 5 you can configure the control by editing the markup on the page. The page editor has IntelliSense support for ASP.NET controls. If you’re using Entity Framework 6 you should also be using the EF6-compatible version of the Entity Data Source control, available as the Microsoft.AspNetEntityDataSource package in NuGet.
Now this threw me a bit because I thought that I had all my updates in place but I went back to NuGet and double checked and did a full refresh of anything I could to make sure that VS knew it was there an verified everything was in place and on 6 as intended. Then I noted in the update tab there was three items there that I could put up (Bootstrap 4.0.0-alpha2, Microsoft.AspNet.Idntity.EntityFramwork v3.0.0-rc1-final, and Microsoft.NetCompliers v1.2.0-rc). This I attempted but that bombs out with the error:
Failed to add reference to 'System.Runtime'. Please make sure that it is in the Global Assembly Cache.
I'm a bit stumped here... no path forward no path backward that I can see.

Make T4MVC work with ASP.NET 5

According to the latest comments in this thread, .tt templates will now after all be supported in ASP.NET 5 starting with Visual Studio Update 1.
Which IMHO would be great because after using T4MVC for years, I certainly don't wanna go back to using magic strings for route/view names (error prone and not refactoring-friendly).
However, I can't quite get it to work with ASP.NET 5 RC and Visual Studio Professional 2015 Update 1.
Here's what I've tried:
Adding the T4MVC NuGet (3.16.5) to a blank ASP.NET 5 solution: nope, CoreCLR complains and no .tt files are added to project:
Error NU1002 The dependency T4MVCExtensions 3.16.5 in project
WebApplication1 does not support framework DNXCore,Version=v5.0.
Add the NuGet to a classic ASP.NET 4.6 solution and manually copy over T4MVC.tt, T4MVC.tt.hooks.t4 and T4MVC.tt.settings.xml to the ASP.NET 5 solution: Visual Studio indeed offers to "Run Custom Tool" on the .tt file....
... but running the transformation throws a NullReferenceException:
Severity Code Description Project File Line Suppression State
Error Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.GetProjectItem(ProjectItems items, String subPath) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 1398
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.GetProjectItem(Project project, String name) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 1378
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.ProcessAreas(Project project) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 600
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.PrepareDataToRender(TextTransformation tt) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 557
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.TransformText() in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 40 WebApplication3 c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt 1398
Any other suggestions?
See also this related question about alternatives to T4MVC in ASP.NET 5.
As David Ebbo (hey!) pointed out, R4MVC - a side project was started a long time ago, but was stalled due to (at the time) breaking changes in the Roslyn compiler.
Luckily, the project was revived, and R4MVC has just released it's first alpha build, with more changes coming soon.
While the project works somewhat differently, and isn't using t4 templates, the end result is the same, and we're working to achieve feature parity with T4MVC in the near future.
At this point, T4MVC is not designed to run on ASP.NET 5 projects, so I'm not surprised that it doesn't work.
A while back, a separate R4MVC project was started, using a Roslyn based approach. However, this was done at a time when there was no T4 support with ASP.NET 5, and that has now been revisited.
So it's possible that there is hope to get T4MVC running on there, but someone would need to invest the time to see how far it is from working.
I just took a tiny step and fixed the null ref that you hit (not yet released, you'll need to hand fix). However, I then hit a condition where it seems to hand altogether.
Anyway, this is not the place to fully investigate all issues, but if someone wants to take that on, we can discuss on https://github.com/T4MVC/T4MVC.

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