asp.net-web-api

webApi parameters data-length

人走茶凉 提交于 2020-01-03 02:29:12
问题 How can I configurate WebApi Controller to read all data that passed in as a parameter? Client: $.post(url,{id:aHugeData}); Controller: public class myController : ApiController { public List<string> Events(List<Event> id) //there must be 30 items, but I see 7 { List<string> artists = new List<string>(); foreach (Event e in id) { artists.AddRange(e.artists.artist); } artists = artists.Distinct().ToList(); return artists; } } in HttpContext I see that all data received. 回答1: Form Url Encoded

Exception in HttpControllerDispatcher

戏子无情 提交于 2020-01-03 02:22:54
问题 In my WebApiConfig::Register(...) I replaced the HttpControllerSelector with my own controller selector. When I fire off a POST request the SelectController member is correctly called and I return a ControllerDescriptor with the correct type of my controller. But then HttpControllerDispatcher is raising an exception saying "The given was not present in the dictionary." Anyone has an idea how to debug such error? The complete exception is message is: The given key was not present in the

WebAPI OData Actions Sample - Differentianting between CheckOut and CheckOutMany actions

心已入冬 提交于 2020-01-03 02:08:42
问题 I've been busy doing my own customisations to a T4 template so that I can have strongly typed OData action invocation from a .NET client. It will probably be my first open source thing that I create :) Anyway, I've testing and developing against the WebAPI OData sample for OData actions called "ODataActionsSample". For those who want to play along at home you can find the samples at http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/ODataActionsSample/. The sample has several more

HTTP Post multiple objects through PostAsJsonAsync

让人想犯罪 __ 提交于 2020-01-03 01:25:07
问题 I'm using HttpClient with some WebAPI. I need to send multiple objects to a POST, here's how my Post method is declared: public string Post(Models.Client value, App.ControlCenter.Models.Company c) { ... } And here's how I'm calling to the WebAPI: using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var s = client

Self referencing loop detected for property in WebApi 2

烂漫一生 提交于 2020-01-02 20:11:11
问题 I've created a Web Api to save new products and reviews in database. Below is the WebApi code: // POST api/Products [ResponseType(typeof(Product))] public IHttpActionResult PostProduct(Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Products.Add(product); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = product.ProductId }, product); } Product class- public class Product { public int ProductId { get; set; } [Required] public string Name { get;

File download from SFTP server on ASP.NET page

一笑奈何 提交于 2020-01-02 20:08:42
问题 I have SFTP server on Ubuntu 16.04 and a site with REST API on ASP Core 2.0. The problem is that I want to provide a straight link to a file on the server, but I don't know how to do it. I suppose it has to be done by API, but what the way? I can download the file by API and give it to the user, but there will be twice time (for download by API from the server and by user from API). And I saw on some sites a link to the file with some access token. May be I should use this way? Any ideas? 回答1

Azure AD application roles

拥有回忆 提交于 2020-01-02 19:28:08
问题 I'm trying to create a protected controller via Azure AD application roles. Here is an exempt from Startup.Auth, which is basically provided by Visual Studio template: public void ConfigureAuth(IAppBuilder app) { ApplicationDbContext db = new ApplicationDbContext(); app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions()); app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions

How could I Encrypt OData Request Payload at Client Side(DataServiceContext) and Decrypting Request at ServerSide?

别等时光非礼了梦想. 提交于 2020-01-02 19:26:22
问题 I have an Windows Application consuming OData v4 WebAPI using DataServiceContext . WebApi is over SSL but still I think anyone can trap request using Web Debugging Tools like fiddler (on the Windows Application Host Machine) and can re-issue the request by altering Request Body. So I was just thinking what if I could encrypt RequestBody of outgoing Request in Windows Application using Public/Private Key in Production Environment. If yes how could I? Do I need to create custom

dotnet publish doesn't include files generated during post build event

对着背影说爱祢 提交于 2020-01-02 19:11:06
问题 Here is part of my A.csproj : <ItemGroup> <Content Include="..\..\Payloads\**\*.*"> <Link>Payloads\%(RecursiveDir)%(FileName)%(Extension)</Link> <CopyToOutputDirectory>None</CopyToOutputDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> </Content> </ItemGroup> Payloads directory is created in a project B which is referenced from project A B.csproj <PropertyGroup> <PostBuildEvent> xcopy /I /S /R /Y /d $(TargetDir)*.* $(SolutionDir)Payloads\Content </PostBuildEvent> <

Upload image using ASP.NET WebAPI using a model

核能气质少年 提交于 2020-01-02 17:46:49
问题 I am trying to upload an image from my windows phone 8 app to the SQL server database using a WebAPI. I am using a model class for the Images, which simply consists of an ID belonging to the item the image is for, the name of the image and a byte array to hold the image itself. I use a WebClient object to access the WebAPI method. When I try to upload the image, it throws the exception as shown below. Does anyone have an idea why it errors? Also, I am open to other methods of storing the