asp.net-core-2.0

AddEntityFrameworkStores can only be called with a role that derives from IdentityRole in .NET Core 2.0

蓝咒 提交于 2020-06-13 17:34:48
问题 I have changed a project from the .NET Core 1.1 to 2.0 version, but I'm getting an error from the Identity, when It tries to add the stores: services.AddIdentity<ApplicationUser, IdentityRole<long>>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); The thrown error is: AddEntityFrameworkStores can only be called with a role that derives from IdentityRole These are my classes: public class ApplicationUser : IdentityUser<long> { } public class ApplicationDbContext

File upload with ASP.Net Core 2.0 Web API and React.js

浪尽此生 提交于 2020-06-09 11:39:27
问题 I'm new to both react.js and ASP.Net core 2.0. And now writing a project using ASP.Net core 2.0 as back end API and react.js as application interface (front end). I'd like to know how to upload file. I have tried as follow but in the Back end side the parameter value (IFromFile file) is always null. And it seems that file was not posted correctly. Here are my codes: .Net core (API) [HttpPost] [Route("upload")] public async Task Upload(IFormFile file) { if (file == null) throw new Exception(

What is the difference between UseStaticFiles, UseSpaStaticFiles, and UseSpa in ASP.NET Core 2.1?

风格不统一 提交于 2020-06-07 09:11:07
问题 ASP.NET Core 2.1.1 offers several seemingly related extension methods for appBuilder: UseStaticFiles from Microsoft.AspNetCore.StaticFiles UseSpaStaticFiles from Microsoft.AspNetCore.SpaServices.Extensions UseSpa from Microsoft.AspNetCore.SpaServices.Extensions Please help me make sense of their purpose and relation to each other? Also, is there any difference from the server execution standpoint if I run these methods in a different order (e.g. app.UseStaticFiles() -> app.UseSpaStaticFiles()

How do you encrypt a password within appsettings.json for ASP.net Core 2?

时间秒杀一切 提交于 2020-05-26 06:00:46
问题 I'd like to use my appsettings.json to store a "master password". This master password would then be used to open up a private key (and its subsequent password store) generated by this excellent password store package: https://github.com/neosmart/SecureStore The problem is, I can't think of any way to encrypt the master password. I know in .NET 4.5, it was possible to do the following: 1) Place your password into the web.config file 2) Run this script: aspnet_regiis.exe -pef appSettings "C:

How do you encrypt a password within appsettings.json for ASP.net Core 2?

梦想与她 提交于 2020-05-26 06:00:28
问题 I'd like to use my appsettings.json to store a "master password". This master password would then be used to open up a private key (and its subsequent password store) generated by this excellent password store package: https://github.com/neosmart/SecureStore The problem is, I can't think of any way to encrypt the master password. I know in .NET 4.5, it was possible to do the following: 1) Place your password into the web.config file 2) Run this script: aspnet_regiis.exe -pef appSettings "C:

Retrofit getting 400 bad request in local iis server but 200 in post man

醉酒当歌 提交于 2020-05-17 07:49:07
问题 I have local asp .net core 2 IIS server. I am getting result when I am using post request. But I am getting error 400 when I am trying to request from andorid using retrofit2. My android device and server are connected to same wifi network postman returns retrofit return I am using my server pc ip instead of localhost for retrofit because retrofit does not support local host retrofit client @POST("/Auth/authenticate") Call<ApiResponse> createAccount(@Body Request user); retrofit call request

Asp.net Core 2.0 with .net framework 4.6.1 - Cannot find reference assembly '.NETFramework/v4.6.1/Microsoft.CSharp.dll

巧了我就是萌 提交于 2020-05-13 06:25:47
问题 I have recently upgraded my project from asp.net core 1.1 to asp.net core 2.0. and app us using .Net framework 4.6.1. Application is working as expected on local dev machine but once it deployed to server with dotnet publish command I am seeing this error InvalidOperationException: Cannot find reference assembly '.NETFramework/v4.6.1/Microsoft.CSharp.dll' file for package Microsoft.CSharp.Reference I have also noticed that ref folder that use be present when using asp.net core 1.1 when

BuildFile Error In Rotativa.aspnetcore

纵然是瞬间 提交于 2020-05-13 05:38:50
问题 While converting a view as pdf in asp.net core 2.1 app with rotative it gives an error Value cannot be null. Parameter name: path1 Below is my Code var rpt = new ViewAsPdf(); //rptLandscape.Model = Model; rpt.PageOrientation = Rotativa.AspNetCore.Options.Orientation.Landscape; rpt.PageSize = Rotativa.AspNetCore.Options.Size.A4; rpt.ViewName = "Test"; byte[] arr = await rpt.BuildFile(actionContextAccessor.ActionContext); System.IO.File.WriteAllBytes(Path.Combine(env.WebRootPath, "PDFStorage",

Export to Excel in ASP.Net Core 2.0

点点圈 提交于 2020-05-10 04:11:42
问题 I used to export data to excel in asp.net mvc using below code Response.AppendHeader("content-disposition", "attachment;filename=ExportedHtml.xls"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.ms-excel"; this.EnableViewState = false; Response.Write(ExportDiv.InnerHtml); Response.End(); When this Code Run it create a file and ask for a location to save I tried working with NPOI and create Excel file very well but cant

How to correctly and safely dispose of singletons instances registered in the container when an ASP.NET Core app shuts down

我与影子孤独终老i 提交于 2020-04-18 05:35:50
问题 I am looking for guidance on how to correctly and safely dispose of registered singleton instances when my ASP.NET Core 2.0 app is shutting down. According to the following document, if I register a singleton instance (via IServiceCollection) the container will never attempt to create an instance (nor will it dispose of the instance), thus I am left to dispose of these instances myself when the app shuts down. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view