Posts

Showing posts from 2017

ASPNETCORE_ENVIRONMENT in Published Project

Typical Program.cs         public Startup(IHostingEnvironment env)         {             // https://blog.elmah.io/config-transformations-in-aspnetcore/             // https://andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/             // https://github.com/aspnet/Hosting/issues/863             // For dev, please remove or rename appsettings.production.json, so that it's not used             var builder = new ConfigurationBuilder()                 .SetBasePath(env.ContentRootPath)                 .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)                 .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)                 .AddEnvironmentVariables();             Configuration = builder.Build();         } Please note: ASPNETCORE_ENVIRONMENT settings in Properties\launchSettings.json only affects debugging by using Visual Studio or C:\projectfolder>dotnet

Errors in Net Core Add-Migration

Visual Studio 2017 version 15.5.2, Net Core 2. Add-Migration error: Exception calling "SetData" with "2" argument(s): "Type  'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in  assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=15.0.0.0,  Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\wanj\.nuget\packages\entityframework\6.2.0\tools\EntityFramework.psm1:720 char:5 +     $domain.SetData('project', $project) +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException     + FullyQualifiedErrorId : SerializationException Exception calling "SetData" with "2" argument(s): "Type  'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in  assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Impl

Set up Visual Studio 2017 for .Net Core Application Development

Image
The Default Profile setting in LibPrograms/Properties/LaunchSettings.json {   "iisSettings": {     "windowsAuthentication": true,     "anonymousAuthentication": true,     "iis": {       "applicationUrl": "http://localhost:8000",       "sslPort": 0     },     "iisExpress": {       "applicationUrl": "http://localhost:49497/",       "sslPort": 0     }   },   "profiles": {     "IIS": {       "commandName": "IIS",       "launchBrowser": true,       "environmentVariables": {         "ASPNETCORE_ENVIRONMENT": "Development"       }     },     "IISExpress": {       "commandName": "IIS",       "launchBrowser": true,       "environmentVariables": {         "ASPNETCORE_ENVIRONMENT": "Developme

Use Windows Authentication in Net Core 2.0

This link has everything we need:  Configure Windows authentication in an ASP.NET Core app About the launchsetting.json file See What is launchsetting.json in ASP.NET Core Windows Authentication and Anonymous Authentication can be set through IIS Authorization or launchsetting.json. However launchsetting.json only affects  development time (running through IIS profile) . Once deployed,  it's determined by IIS Authorization setting only. If Windows Authentication is enabled but Anonymous is disabled When Windows authentication is enabled and anonymous access is disabled, the [Authorize] and [AllowAnonymous] attributes have no effect. The above description in  Configure Windows authentication in an ASP.NET Core app  is somehow wrong. In contrast, in a Intranet app where anonymous is disabled, there is no problem to still use [Authorize] to control access based on Windows groups. This pattern is common in real world. Be aware cache issue when testing

Import SQL Server 2016 and Excel Data into SQL Server 2008 R2

Background Development    SQL Server 2016 (“2016”) Database: LibDB     Branch table: (prod data)     Category table: (prod data)     Program table: (fake data) Production SQL Server 2008 R2 (“R2”) Excel Sheet: needs to be imported into Production’s Program table Import 2016 Database into R2 Please note: R2 doesn’t recognized the database backup generated by 2016 Script to Create Database Schema (DB and All Table Structures) 2016 SMS/ LibDB/Tasks/Generate Scripts/ Next /Script entire database and all database objects/ Next /Advanced:     Script for Server Version: SQL Server 2008 R2     Types of data to script: Schema only /OK Run the script on R2 There will be errors in database creation when running this script on R2. Please replace the error lines with similar database creation statements that are generated on R2 itself. Script to Insert Data for Branch and Category Table 2016 SMS/ LibDB/Tasks/Generate Scripts/next/Select specific database objec

TF30063: You are not authorized to access Team Foundation Server

Andrew Beier   SOLVED: I ran into the same issue of TF 30063 on v15.3.5 right after changing my network AD password (enterprise policy). Previously you would be prompted to updated your user credentials for on-prem TFS, however at some point in one of the recent VS patches this appears to have stopped being the case. Even after deleting the connection, closing VS, and going back in and trying to add again the credentials wouldn't change. The issue was that my previous credentials were cached by the Windows OS for the TFS server. While some people might have had success wiping out the AppData temp folders, that is not required. You need to update the credentials through Control Panel on the Windows OS. For me on Windows 10: Close VS. Go to Control Panel (with small icon view)-->User Accounts-->Manage your credentials (on the left column)-->Select "Windows Credentials"-->Scroll down to the "Generic Credentials" section and look for your TFS serv

Use GnuPG Tools or C# Code for PGP Encryption and Signature

For PGP encryption and signature, usually we use PGP command line tools for test purpose and finally use C# application for production. Mine is a Net Core 2.0 console application using NuGet package PgpCore,  https://github.com/mattosaurus/PgpCore. PgpCore is based on BouncyCastle.NetCore which supports the standard OpenPGP keys. Here w use the popular GnuPG (GPG) tools to generate OpenPGP key pair. Download and Install GPG for Windows Download from  https://gpg4win.org/download.html . By default the installation will create two folders (here we use command line tools only): Gpg4Win UI (Kleopatra): C:\Program Files (x86)\Gpg4win Command line tools: C:\Program Files (x86)\GnuPG\bin Generate a GPG Key Pair For GnuPG 2.2.1 and above:     C:\Program Files (x86)\GnuPG\bin> gpg --full-generate-key For old versions of GnuPG:     C:\Program Files (x86)\GnuPG\bin> gpg --gen-key Common GPG Commands List public keys: gpg --list-key or gpg -k List private keys: gpg

Install Win32 OpenSSH and Enable Public Key Authentication

Setup of a SFTP server is much more complicated than FTPS. To have a full featured SFTP server, OpenSSH seems to be  the only option. The original OpenSSH is for Unix only.  Fortunately Win32 OpenSSH was  recently released by Microsoft though for testing only. Here I use SFTPServer  as SSH Server while SFTPClient as SSH client. 1. Server side Installation C:\Program Files (x86)\OpenSSH>net start sshd https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH This tutorials works. Note 1. Generation and Use of Host Keys Host keys are generated by .\ssh-keygen.exe -A. Host key are stord in  C:\Program Files (x86)\OpenSSH on server. http://man7.org/linux/man-pages/man1/ssh-keygen.1.html -A For each of the key types (rsa1, rsa, dsa, ecdsa and ed25519) for which host keys do not exist, generate the host keys with the default key file path, an empty passphrase, default bits for the key type, and default comment.

Confusing Concepts about SFTP: SSH2 vs OpenSSH

Credit and copied from https://dada.tw/2008/01/03/70/ Terminology: SSH Protocols and Products SSH A generic term referring to SSH protocols or software products. SSH-1 The SSH protocol, Version 1. This protocol went through several revisions, of which 1.3 and 1.5 are the best known, and we will write SSH-1.3 and SSH-1.5 should the distinction be necessary. SSH-2 The SSH protocol, Version 2, as defined by several draft standards documents of the IETF SECSH working group. SSH1 Tatu Ylönen's software implementing the SSH-1 protocol; the original SSH. Now distributed and maintained (minimally) by SSH Communications Security, Inc. SSH2 The "SSH Secure Shell" product from SSH Communications Security, Inc. This is a commercial SSH-2 protocol implementation, though it is licensed free of charge in some circumstances. ssh (all lowercase letters) A client program included in SSH1, SSH2, OpenSSH, F-Secure SSH, and other

My Simple Upload Program using FTPs (Net Core 2.0 and Visual Studio 2017 v15.3.5)

1. FTPS Server is built in IIS7 2. FtpWebRequest seems to work well in Net Core v2 using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using FTPs.Models; using System.Net; using System.IO; using System.Text; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; namespace FTPs.Controllers {     public class HomeController : Controller     {         public X509Certificate2 FindCertificateFromStore(X509FindType findType, string findValue)         {               //W10: type certificate to search and select Manager User Certificates               X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);             store.Open(OpenFlags.ReadOnly);             // https://stackoverflow.com/questions/8448147/problems-with-x509store-certificates-find-findbythumbprint          
Upgrading NetCore from v1.1.0 to v2.0.0 in Visual Studio 2017 Note: Any time if you see "Package restore failed. Rolling back package changes", please seelct Tools/Options:  NuGet Package Manager/General/Clear All NuGet Cache(s) Select Project / Manage Nuget Packages Step 1 Update.csproj Change     <TargetFramework>netcoreapp1.1</TargetFramework> To:     <TargetFramework>netcoreapp2.0</TargetFramework> Note: if this is not changed, you'll receive error "Package restore failed. Rolling back package changes" Step 2 Update all installed packages In NuGet Package Manager, select Updates tab, select All package and click Update Step 3 Install-Package Microsoft.EntityFrameworkCore.SqlServer See https://docs.microsoft.com/en-us/ef/core/ After done, all packages references in .csproj will be automatically updated to v2.0 For all other errors, please refer to the following must reading sites: https://docs

Two easy ways to resolve the failure in SelectedValue in MVC DropDownList

Two easy ways to resolve the failure in SelectedValue in MVC DropDownList Scaffolding my Net Core project using Visual Studio 2017 : Model public class Site   {          public int Id { get; set; }          public string Name { get; set; }          public virtual ICollection<Lease> Leases { get; set; }   } public class Lease     {         public int Id { get; set; }         public string Name { get; set; }         public int SiteId { get; set; }         public virtual Site Site { get; set; }     } Create.cshtml  <select asp-for="SiteId" class="form-control" asp-items="ViewBag.SiteId">      <option>Please select site</option>  </select> LeasesController.cs         // GET: Leases/Create         public async Task<IActionResult> Create(int? defaultSiteId)         {             ViewData["SiteId"] = new SelectList(await GetSiteSelectList(), "Id", "Name", defaultSiteI