天道酬勤,学无止境

asp.net-core-2.0

Configure Column Options for Serilog Sinks MsSqlServer in AppSettings.json

I'm trying to determine if it's possible to configure the column options for serilog sink mssqlserver in the appsettings.json file for an ASP.Net Core 2 project. I create and configure the logger in the Program.cs file. public static IConfiguration Configuration { get; } = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true) .AddEnvironmentVariables() .Build(); public static

2021-06-24 07:52:49    分类:问答    asp.net-core-2.0   appsettings   serilog

Launch external process (.exe) from asp.net core app

I have the following [HttpPost] public IActionResult LaunchExternalProcess() { Process.Start("C:\\Windows\\System32\\calc.exe"); return Ok(); } And this works perfectly fine on my local machine, but when deployed onto IIS 10 (windows 2016) I get no errors but it does not launch the calc on the server. I simply want to call an external .exe from a button on my page. Here is the javascript that I am using which also works on my local but no errors on server and it displays the success message $.ajax({ url: "/Admin/LaunchExternalProcess", type: "POST", cache: false, success: function () { console

2021-06-23 19:26:22    分类:问答    iis   asp.net-core   asp.net-core-mvc   asp.net-core-2.0   kestrel-http-server

.NET Core 2.0 and xUnit doesn't run

Visual Studio 2017 + .NET Core 2.0. I created a brand new xUnit test project from the template: Project (.csproj) file: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> <PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit.runner.console" Version="2.3.1" /> </ItemGroup> </Project> Test public class Class1 { [Fact]

2021-06-23 13:55:25    分类:问答    .net-core   asp.net-core-2.0   xunit

String Trim Model Binder in ASP .NET Core 2

I'm working on a .NET Core 2 API project and have been trying to implement a universal string trim model binder that would trim all string values of provided request parameters and field values. So far I have had mixed results and am struggling to find working example that would point me in the right direction. I've been trying to implement the same model binder as posted by Vikash Kumar. This model binder works fine for all string values that are passed into controller actions via direct parameters, such as public IActionResult Profile(string username), but for string fields in complex

2021-06-23 10:16:37    分类:问答    asp.net-core   asp.net-core-2.0   asp.net-core-webapi

How do I get JWT working in Autorest generated SDK? (ASP.NET Core 2.0)

I want to be able to login to my identity database with user name and password and retreive a JWT. Then I want to use the JWT to access data securely from my API. I found out that the SDK code generated by VS2017 uses an old version of autorest, so I have switched to using Azure Autorest The api and the SDK are both ASP.NET Core 2.0 To generate the SDK I use AutoRest -mynamespace mytrack.Client -CodeGenerator CSharp -Modeler Swagger -Input swagger.json -PackageName mytrack.client -AddCredentials true The versions show as AutoRest code generation utility [version: 2.0.4262; node: v8.11.2] I

2021-06-23 09:55:06    分类:问答    c#   rest   jwt   asp.net-core-2.0   autorest

When using an API route, return Http Response 401 instead of redirect to login page when not authorised

I'm building an ASP.NET Core 2.0 website using MVC and WebAPI to provide access to a series of microservices. Where a WebAPI controller requires a user to be authenticated and authorised (using the Authorize attribute), any unauthorised or not-logged in user gets the response back as the entire HTML for the MVC login page. When unauthorised users access the API, I would like to return the HTTP status code 401 and its associated error message in the response, instead of an entire HTML page. I've looked at a few existing questions and noticed that they either refer to ASP.NET MVC (such as

2021-06-23 03:25:52    分类:问答    httpresponse   asp.net-core-2.0   asp.net-core-webapi   http-status-code-401

BuildFile Error In Rotativa.aspnetcore

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", "File.pdf"), arr); Although it returns webpage as pdf successfully, but I want to store it inside a

2021-06-23 02:26:34    分类:问答    c#   asp.net-core   asp.net-core-2.0   rotativa

.NET Core override controller level Authorize attribute for a specific action

Here is an example controller to explain the case [Authorize] public class AccountController : ControllerBase { [AllowAnonymous] [Authorize(Policy = "SpecificPolicy")] public string MethodA() {} public string MethodB() {} } MethodA should only be authorized via "SpecificPolicy". MethodB should be authorized via the Authorized attribute The issue I'm having is that if I remove the AllowAnonymous attribute then Authorize on the controller takes precedence which I don't want for MethodA. When I keep AllowAnonymous for MethodA then Authorize(Policy = "SpecificPolicy") is ignored.

2021-06-22 22:44:15    分类:问答    .net-core   asp.net-core-2.0

How to use ASP.NET Core Identity without roles?

Is it feasible to implement identity in asp.net core 2 without roles implementation? I have tried to implement the following: services.AddIdentityCore<TUser>(); but that does not seem to work as well.

2021-06-22 11:45:20    分类:问答    c#   asp.net-core   asp.net-core-2.0   asp.net-core-identity

How to set default datetime format for .net core 2.0 webapi

Currently in my local. The API is expecting the same formart as in SQL Server database which is yyyy-mm-dd. However when i am deploying the application into production server. The API is expecting the datetime format as yyyy-dd-mm. Is there any way to configure my .net core web api to accept yyyy-mm-dd as default format in every enviroment?

2021-06-22 07:35:19    分类:问答    .net-core   asp.net-core-2.0   asp.net-core-webapi