asp.net-core-2.1

POST actions in [ApiController] in ASP.NET Core 2.1

荒凉一梦 提交于 2020-01-03 17:24:09
问题 I have the following ASP.NET Core 2.1 Api controller: [Route("api/[controller]")] [ApiController] public class ImagesController : ControllerBase { [HttpPost("[action]")] public async Task<IActionResult> Upload([FromForm]ICollection<IFormFile> files) { ... } [HttpGet("thumbnails")] public async Task<IActionResult> GetThumbNails() { ... } Both the GET and POST actions worked with Postman. However, the POST action would not work with the UI: the action would always receive a files parameter

Problems running/configure self hosted console application (ASP.net core 2.1, Kestrel) with public certificate on a windows webserver

≡放荡痞女 提交于 2020-01-02 17:54:07
问题 I have developed various webservices in the past (VB ASP.net web-api applications) with https for production. I have done the development with http and then setup https on the production servers. To setup a port on the production server for https and the certificate, I have: Imported a public certificate in the certificate store on the windows server configured a specific port for https with netsh. E.g: netsh http add urlacl url=https://+:22224/ user=everyone bound the certificate (over the

Change Bound Property in OnPost in model is invalid

天大地大妈咪最大 提交于 2020-01-02 10:32:48
问题 I am using ASP.NET Core Razor Pages and I want to add a counter for a number of attempts it takes a user complete a task. I am using: [BindProperty] public int Attempts { get; set; } And inside the OnPost I am doing this: public IActionResult OnPost() { if(!IsCorrect()) { Attempts++; return Page(); } return RedirectToPage($"./Index") } I expected this to update the data on the client side, since without [BindProperty] & return Page() , data would be lost if the model was invalid. However,

Change Bound Property in OnPost in model is invalid

余生颓废 提交于 2020-01-02 10:31:40
问题 I am using ASP.NET Core Razor Pages and I want to add a counter for a number of attempts it takes a user complete a task. I am using: [BindProperty] public int Attempts { get; set; } And inside the OnPost I am doing this: public IActionResult OnPost() { if(!IsCorrect()) { Attempts++; return Page(); } return RedirectToPage($"./Index") } I expected this to update the data on the client side, since without [BindProperty] & return Page() , data would be lost if the model was invalid. However,

ASP Core HttpClientFactory Pattern Use Client Cert

纵饮孤独 提交于 2020-01-02 05:26:08
问题 Any one know how to use client cert when using the HttpClientFactory ? In all the examples I've found you need to provide an HttpMessageHandler in the HttpClient constructor, which isn't available when using the HttpClientFactory services.AddHttpClient("NamedClient", client => { var handler = new HttpClientHandler(); X509Certificate2 certificate = GetMyX509Certificate(); handler.ClientCertificates.Add(certificate); client. // ?? How do I set the handler? }); 回答1: I was able to get it working

ASP Core HttpClientFactory Pattern Use Client Cert

老子叫甜甜 提交于 2020-01-02 05:26:02
问题 Any one know how to use client cert when using the HttpClientFactory ? In all the examples I've found you need to provide an HttpMessageHandler in the HttpClient constructor, which isn't available when using the HttpClientFactory services.AddHttpClient("NamedClient", client => { var handler = new HttpClientHandler(); X509Certificate2 certificate = GetMyX509Certificate(); handler.ClientCertificates.Add(certificate); client. // ?? How do I set the handler? }); 回答1: I was able to get it working

How to use OData in ASP.NET Core 2.1?

て烟熏妆下的殇ゞ 提交于 2019-12-25 17:46:53
问题 I try to use OData in an ASP. Bellow my code: //============== Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddDbContext<EntriesContext>( opt => opt.UseMySql("server=localhost;database=mydb;user=myusr;password=mypass", mysqlOptions =>{mysqlOptions.ServerVersion(new Version(5..), ServerType.MySql);})); services.AddOData(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); ... } public void Configure(IApplicationBuilder app,

EF Core - Connection string cannot be null

冷暖自知 提交于 2019-12-25 03:35:09
问题 I am using ASP.Net Core 2.1 with EF Core 2.1 While running any Migration from PMC, I am getting the below error Value cannot be null. Parameter name: connectionString This is how my Context class looks like public class MyAppContextFactory : IDesignTimeDbContextFactory<MyAppContext> { private readonly string _dbConnection; public MyAppContextFactory() { } public MyAppContextFactory(string dbConnection) : this() { _dbConnection = dbConnection; } public MyAppContext CreateDbContext(string[]

EF Core - Connection string cannot be null

ぐ巨炮叔叔 提交于 2019-12-25 03:35:03
问题 I am using ASP.Net Core 2.1 with EF Core 2.1 While running any Migration from PMC, I am getting the below error Value cannot be null. Parameter name: connectionString This is how my Context class looks like public class MyAppContextFactory : IDesignTimeDbContextFactory<MyAppContext> { private readonly string _dbConnection; public MyAppContextFactory() { } public MyAppContextFactory(string dbConnection) : this() { _dbConnection = dbConnection; } public MyAppContext CreateDbContext(string[]

Apply Authorize filter on all controllers within an area

我与影子孤独终老i 提交于 2019-12-25 03:27:40
问题 How can I force authorization on all controllers within an area? Specifically, I would like to configure an AuthorizeFilter to be applied on the 'admin' area as part of the Startup.ConfigureServices() method. 回答1: One way do to this is with the use of a custom IControllerModelConvention public class AuthorizeAreaConvention : IControllerModelConvention { private readonly string _area; private readonly string _policy; public AuthorizeAreaConvention(string area, string policy) { _area = area;