asp.net-web-api

upload file on server webfolder and post json data at the same using asp.net web api

家住魔仙堡 提交于 2021-02-08 12:01:21
问题 I want to upload files and post json data at the same using asp.net web api, i am not able to figure out how to code for controller to receive json data and file request also not able to figure out how to do setting in postman for testing the same. public async Task<JObject> Save(Validate val) { } 回答1: Uploading a file from web form to server requires a different approach specially when you want to upload file with other model data. Files selected on the client can not be submitted as JSON to

How to download ByteArrayContent of HttpResponseMessage as zip

99封情书 提交于 2021-02-08 11:37:57
问题 I work with Web Api (C#) and angular.js on client. I need to download server response content (ByteArrayContent of zip). I have this method on server: public HttpResponseMessage Download(DownloadImagesInput input) { if (!string.IsNullOrEmpty(input.ImageUrl)) { byte[] imageBytes = GetByteArrayFromUrl(input.ImageUrl); ZipManager manager = new ZipManager(); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); byte[] zipBytes; zipBytes = string.IsNullOrEmpty(input.QrCode) ?

How to download ByteArrayContent of HttpResponseMessage as zip

强颜欢笑 提交于 2021-02-08 11:36:51
问题 I work with Web Api (C#) and angular.js on client. I need to download server response content (ByteArrayContent of zip). I have this method on server: public HttpResponseMessage Download(DownloadImagesInput input) { if (!string.IsNullOrEmpty(input.ImageUrl)) { byte[] imageBytes = GetByteArrayFromUrl(input.ImageUrl); ZipManager manager = new ZipManager(); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); byte[] zipBytes; zipBytes = string.IsNullOrEmpty(input.QrCode) ?

HttpControllerContext.Configuration is sometimes null during Content negotiation

删除回忆录丶 提交于 2021-02-08 10:44:22
问题 We are setting up a ASP.NET 4.6.2 Web Api host and noticing that some requests fail because of the following error: HttpControllerContext.Configuration must not be null. I've been unable to reproduce the issue and wanted to ask if anybody could steer me in the right direction? This is the stack trace: [0] System.InvalidOperationException "HttpControllerContext.Configuration must not be null." at System.Web.Http.Results.NegotiatedContentResult`1.ApiControllerDependencyProvider.EnsureResolved()

ASP.NET Core 3.1 WebRoot Path

二次信任 提交于 2021-02-08 10:38:50
问题 I am pushing an external file into the wwwroot folder of my ASP.NET Core 3.1 application. I need to reference the path to provide a constructor variable during the services wire up. In the Startup class I have added the IWebHostEnvironment to the constructor parameters: public Startup(IConfiguration configuration, IWebHostEnvironment env) { Configuration = configuration; _env = env; } When debugging, it seems that _env.WebRootPath returns the path as it is in my source folder, rather than the

Cannot get header that contains a period from NGINX

女生的网名这么多〃 提交于 2021-02-08 10:10:33
问题 The header "Abp.TenantId" is null because of the "." . If remove the "." (like "AbpTenantId" ), it will be ok. How to add a header with a "." ? ======================================================= localhost debug: Provisional headers are shown (show this on client request) Request.Headers.Unknown (show this in server, api action) Request.Headers.MaybeUnknown (show this in server, api action) localhost is ok. The same code in server, but server error. The code for the tenantId : The logs

Cannot get header that contains a period from NGINX

ⅰ亾dé卋堺 提交于 2021-02-08 10:01:33
问题 The header "Abp.TenantId" is null because of the "." . If remove the "." (like "AbpTenantId" ), it will be ok. How to add a header with a "." ? ======================================================= localhost debug: Provisional headers are shown (show this on client request) Request.Headers.Unknown (show this in server, api action) Request.Headers.MaybeUnknown (show this in server, api action) localhost is ok. The same code in server, but server error. The code for the tenantId : The logs

Google reCaptcha in Web API 2 c#

混江龙づ霸主 提交于 2021-02-07 20:22:12
问题 I have an ASP.NET Web API 2 Project. I am trying to read Google Captcha from the form. I tried this Code: public string Post(FoundingRequest model) { var response = Request["g-recaptcha-response"]; string secretKey = "my key"; var client = new WebClient(); var result = client.DownloadString( $"https://www.google.com/recaptcha/api/siteverify?secret={secretKey}&response={response}"); var obj = JObject.Parse(result); model.Captcha = (bool)obj.SelectToken("success"); .... } but I am receiving an

.Net CORE Web API no-cache but still happens

血红的双手。 提交于 2021-02-07 20:17:15
问题 Using .Net Core and visual studio 2015. I have a Web API create in .net core, Recently in testing i realized my results are being cached (or atleast appear to be). So i implimented a response cache and set location to none: [Route("api/[controller]")] public class NopProductController : Controller { private INopProductService _nopProductService { get; set; } public NopProductController(INopProductService nopProductService) { _nopProductService = nopProductService; } [HttpGet] [ResponseCache

Ajax request with custom header sent to Web API server with CORS enabled

纵饮孤独 提交于 2021-02-07 19:41:50
问题 I'm trying to get a Web API webservice setup correctly to use CORS but haven't been having much luck with it lately. I have an html page from a mobile app using an ajax request to fetch some data: Webservices.GetUserLevel = function() { var userLevel = null; $.ajax({ url: _CONNECTION_STRING + "getuserlevel/" + _USER_PIN, contentType:'application/json; charset=utf-8', type: 'GET', async: false, cache: false, crossDomain: true, data: { BlackberryPin: _USER_PIN }, beforeSend: function(xhr) { xhr