スキップしてメイン コンテンツに移動

投稿

ラベル(ASP.NET Core)が付いた投稿を表示しています

[Angular] Upgrade from 8 to 9 and set basehref

Upgrade from 8 to 9 I have had a question. Though I often executed "npm -g update" and Angular ver.9 has already been released, but Angular version in my PC is still 8. Why? Finally I got the reason. I must install @angular/cli again. npm install -g @angular/cli It's same as updating NuGet packages. After installing, I just do "ng update @angular/cli @angular/core" on my project. Angular Update Guide set basehref Because I use IIS, base url becomes like "http://localhost:5000/sample". So when I build Angular product, I must add path to index.html like below. index.html <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Sample</title> <base href=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href=" sample/ favicon.ico"...

[Angular] Error handling of HttpClient

Intro Sometimes I got errors when I had accessed to server with HttpClient. I had wanted to know what should I do, so I tried in some situations. Returning errors sample (ASP.NET Core) Because I had wanted to get some kinds of problems, I used Identity. Startup.cs using Files; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.SpaServices.AngularCli; using Models; using UpgradeSample.Models; using UpgradeSample.Products; using UpgradeSample.Users; public class Startup { private IConfigurationRoot Configuration { get; } public Startup(IHostEnvironment env) { ... } public void ConfigureServices(IServiceCollection services) { // DB Connect services.AddDbContext<UpgradeSampleContext>(options => options.UseNpgsql(Con...

[ASP.NET Core][Angular] Integrate Angular app into ASP.NET Core app

Intro I had written Angular app and ASP.NET Core app separately. But because I had had to use some internal api at my work, I tried to integrate them. Prepare Angular (CLI ver. 8.3.21) ASP.NET Core (ver. 3.1.101) Because Microsoft.AspNetCore.SpaServices of ASP.NET Core had been obsoleted and changed to Microsoft.AspNetCore.SpaServices.Extensions. So there hadn't been so much documents. [Announcement] Obsoleting Microsoft.AspNetCore.SpaServices and Microsoft.AspNetCore.NodeServices #12890 Thus, I had generated sample program of Angular template. And I had followed it to integrate apps. dotnet new angular -n AngularSample Change Angular app Because of Microsoft.AspNetCore.SpaServices.Extensions, I hadn't needed changing the Angular app. Output Path The output path hadn't been same as Angular template's one. angular.json (Angular CLI) ... "outputPath": "dist/{PROJECT-NAME}", ... angular.json (ASP.NET Core) ... "outputPath...

[Angular][ASP.NET Core] Sending data

Intro When I had POST data from the Angular app to ASP.NET Core app, sometimes I failed even though there hadn't been any exceptions happened. Because I had wanted to know the reason, I tried something. What I did Set data to Request Payload and POST Set data to Form Data and POST Get data from ASP.NET Core Sample Codes ASP.NET Core ApiController.cs using System; using System.Collections.Generic; using System.Threading.Tasks; using Files; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Models; using UpgradeSample.Models; using UpgradeSample.Products; namespace UpgradeSample.Controllers { public class ApiController: Controller { private readonly IProductService _productService; public ApiController(IProductService productService) { _productService = productService; } [HttpGet] [Route("/products")] public async Task<List<Product>> GetProducts() {...

[Angular][ASP.NET Core] Upload chunked files

Intro I wanted to send files to Web application (made by ASP.NET Core). If the file size had been small, I didn't need do any special things. But when I tried to send a large file, the error was occurred by ASP.NET Core's limitation. Though I could change the settings, but I didn't want to do that, because I hadn't known the file sizes what would been actually using. So I splitted the data into chunks first, and sent them. After receiving all chunks, I merged them into one file. There might be some libraries or APIs (ex. Stream API) what did them automatically, but I couldn't find them. What I did [ASP.NET Core] Make CORS enabled [Angular] Split a large file into chunks [Angular][ASP.NET Core] Send and receive data as form data [ASP.NET Core] Merge chunks into one file [ASP.NET Core] Make CORS enabled Because the client side application(Angular) and the server side application(ASP.NET Core) had been separated, I had to make CORS(Cross-Origin Requests) ...

[ASP.NET Core 3.0] Sign in with Identity

Today I tried authentication by ASP.NET Core Identity. What I did 1. Create custom IdentityUser 2. Create a route for authentication 3. After authentication, access authorized route Setup Most of all environments were same as previous post. I only installed Microsoft.AspNetCore.Identity.EntityFrameworkCore (ver.3.0.0) by NuGet. Add user table I added user table to DB. CREATE TABLE "User" ( "UserId" serial PRIMARY KEY, "Name" text not null, "Password" text not null ) 1. Create custom IdentityUser First, I created custom IdentityUser for signing in. Because the default IdentityUser had had so many properties. But I only wanted three things below. Id UserName Password ApplicationUser I could created custom user class by inheritting IdentityUser class. ApplicationUser.cs using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.AspNetCore.Identity; names...

Upgrade from ASP.NET Core 2.2 to 3.0

Conguratulations on the releasing .NET Core 3.0 and ASP.NET Core 3.0! Today's theme is about upgrading ASP.NET Core from ver.2.2 to ver.3.0. What I did Creating an empty ASP.NET Core project(ver.2.2.402) Adding EntityFrameworkCore by NuGet Adding some codes Upgrading to ver.3.0.100 Fixing some problems Setup Environments .NET Core : ver.2.2.402, ver.3.0.100 Microsoft.EntityFrameworkCore : ver.2.2.6, ver.3.0.0 Npgsql.EntityFrameworkCore.PostgreSQL : ver.2.2.4, ver.3.0.1 Windows10 : ver.1903 Rider : ver.2019.2.3 PostgreSQL : ver.12.0 Creating the base project UpgradeSample.csproj <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.2</TargetFramework> <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include=...