asp.net-web-api2

Model validation in Web API - Exception is thrown with out a throw statement?

ぃ、小莉子 提交于 2021-01-27 07:41:00
问题 I have seen the model validation from here (Under section: Handling Validation Errors ). The code-snippet is as below in Web API public class ValidateModel : ActionFilterAttribute { public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { if (actionContext.ModelState.IsValid == false) { actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, actionContext.ModelState); } base.OnActionExecuting(actionContext); }

Model validation in Web API - Exception is thrown with out a throw statement?

南笙酒味 提交于 2021-01-27 07:38:19
问题 I have seen the model validation from here (Under section: Handling Validation Errors ). The code-snippet is as below in Web API public class ValidateModel : ActionFilterAttribute { public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { if (actionContext.ModelState.IsValid == false) { actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, actionContext.ModelState); } base.OnActionExecuting(actionContext); }

Model validation in Web API - Exception is thrown with out a throw statement?

帅比萌擦擦* 提交于 2021-01-27 07:37:56
问题 I have seen the model validation from here (Under section: Handling Validation Errors ). The code-snippet is as below in Web API public class ValidateModel : ActionFilterAttribute { public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { if (actionContext.ModelState.IsValid == false) { actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, actionContext.ModelState); } base.OnActionExecuting(actionContext); }

Swashbuckle 5 and multipart/form-data HelpPages

三世轮回 提交于 2021-01-26 04:00:49
问题 I am stuck trying to get Swashbuckle 5 to generate complete help pages for an ApiController with a Post request using multipart/form-data parameters. The help page for the action comes up in the browser, but there is not included information on the parameters passed in the form. I have created an operation filter and enabled it in SwaggerConfig, the web page that includes the URI parameters, return type and other info derived from XML comments shows in the browser help pages; however, nothing

Swashbuckle 5 and multipart/form-data HelpPages

孤街醉人 提交于 2021-01-26 04:00:47
问题 I am stuck trying to get Swashbuckle 5 to generate complete help pages for an ApiController with a Post request using multipart/form-data parameters. The help page for the action comes up in the browser, but there is not included information on the parameters passed in the form. I have created an operation filter and enabled it in SwaggerConfig, the web page that includes the URI parameters, return type and other info derived from XML comments shows in the browser help pages; however, nothing

How to use Json data type in C# Entity Framework model?

北城余情 提交于 2021-01-23 01:48:54
问题 model.cs [Column(TypeName = "json")] public string application_role { get; set; } Its MySQL, data type of particular column is json , and how to add it in a model class. I tried with DataAnnotations but getting error as The specified type member 'application_role' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Linq Query to get data context.sc_employee_details .Where(e => e.user_name.Equals(userName)) .Select(o => o

How to use Json data type in C# Entity Framework model?

时光怂恿深爱的人放手 提交于 2021-01-23 01:46:53
问题 model.cs [Column(TypeName = "json")] public string application_role { get; set; } Its MySQL, data type of particular column is json , and how to add it in a model class. I tried with DataAnnotations but getting error as The specified type member 'application_role' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Linq Query to get data context.sc_employee_details .Where(e => e.user_name.Equals(userName)) .Select(o => o

Publishing .netcore angular project gives “The SPA default page middleware could not return index.html”, works in debug

不羁岁月 提交于 2020-12-30 03:56:46
问题 We've inherited a small .net core application that has an angular 8 front end and a web api back end. When i received the files they were two separate projects, but to keep them similar to the rest of our projects, and make our deployments easier, we would like to combine them into one visual studio solution / project. I've brought the files into visual studio and done various things to try get the project working. I've been on this about a day now, so i couldn't completely tell you exactly

Upload file through WebApi fails for larger file

自古美人都是妖i 提交于 2020-12-26 08:16:33
问题 I'm trying to upload a file using WebApi. The byte[] is 1.6MB. For some reason my model is serialised to null. I suspect it's the filesize because it works with smaller files. Any ideas? This is what I'm using - where data is a model containing a byte[]. return HttpClient.PostAsJsonAsync<T>(requestUri, data) .ContinueWith(x => Handle<R>(x.Result), TaskContinuationOptions.AttachedToParent); 回答1: May be you have to change .config <system.web> <httpRuntime maxRequestLength="2097152"/> </system

Simplest way to add Basic authentication to web.config with user/pass

不羁岁月 提交于 2020-12-25 03:50:24
问题 I'm setting up an Azure API Management with with an ASP.NET WebApi 2 app behind it. API Management recommends setting up Basic auth between the API Management proxy and the ASP.NET WebApi to make sure the WebApi is only accessible through the API Management proxy. (Of course OAuth tokens will be still sent with requests for the "real" authentication, but I'll add that later.) With this in mind, I don't really want to implement the Basic auth in the application, I would like to have it handled