Skip to main content

Posts

Showing posts from 2017

Create aspnet core 2.0 Identity entity framework Sql Server database schema

When running aspnet core 2.0 identity application, I have encountered the error "invalid object AspNetUsers", which means the database table is not created. In order to create database schema required by aspnet core 2.o identity framework, following these steps: 1. In your project, create data context related to identity: public class UserDbContext : IdentityDbContext < IdentityUser > { public UserDbContext (DbContextOptions< UserDbContext > options) : base (options) { } protected override void OnModelCreating( ModelBuilder builder) { base .OnModelCreating(builder); } } 2. In Startup.cs file, configure the Identity store and UserDbContext entity framework: var secretKey = Configuration.GetSection("JWTSettings:SecretKey").Value; var issuer = Configuration.GetSection("JWTSettings:Issuer").Value; var audience = Configuration.GetSection("JWTSet...

Define multiple Angular apps in MVC layout and content page

Here is the situation I encountered: I have a MVC application, in layout.cshtml file, I have a header logo and footer logo and I want the logos to be dynamic based on the client information passed in. Here is my layout page: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>For your security - Mercer.MFA.SharedUI</title> <base href="~/" /> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /> <link rel="stylesheet" href="~/css/magic-check.css" /> <link rel="stylesheet" href="~/css/site.css" /> </head> <body> <div class="container"> <header ng-app=" headerApp " ng-controller=" headerCtrl "> <div class="row"> <div class="col-md-6 header_left...

MVC Render Partial View to HTML inside controller

We know that we can use @Html.Partial("PartialViewName") to render partial view in view. However, sometimes we need to render the partial view to HTML inside the controller. For example, I have a ChoiceResultsPartial which displays the choices that user has made. I also want to send the results to the email address the user provides. The best way to achieve this is to use the same way as @Html.Partial() to get the HTML and send the HTML as email body. In order to achieve this, we can use following code:         public string RenderViewToString( string viewName, object model, TempDataDictionary tempData)         {             if ( string .IsNullOrEmpty(viewName))                 viewName = this .ControllerContext.RouteData.GetRequiredString( "action" );             var viewData = new ViewDataDictionary(model);     ...