asp.net-web-api

Re size image not working C# [duplicate]

狂风中的少年 提交于 2019-12-25 11:15:16
问题 This question already has answers here : Resize image proportionally with MaxHeight and MaxWidth constraints (3 answers) Closed 6 years ago . Am re sizing an image with the following code using (Image thumbnail = new Bitmap(100, 50)) { using (Bitmap source = new Bitmap(imageFile)) { using (Graphics g = Graphics.FromImage(thumbnail)) { g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality;

Applying a Contract Resolver to a specific model via an attribute

ぃ、小莉子 提交于 2019-12-25 09:45:21
问题 I am using Web API which internally uses Json.Net. Currently, I have a scenario where I need to apply a custom contract resolver only to one specific model. I can apply a custom JsonConverter using an attribute like [JsonConverter(typeof(MyConverter))] . Is it possible to apply a custom contract resolver on one model in the same way? In my scenario, I need to be able to use [JsonProperty] attributes during deserialization but ignore them during serialization, just for one of my model classes.

WebApi controller gives nulls

拈花ヽ惹草 提交于 2019-12-25 09:40:12
问题 Ok here's my route Config.Routes.MapHttpRoute( name: "Default", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); And my controller public class GameController : ApiController { internal static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); [HttpGet,HttpPost] public IEnumerable<HostedGame> List() { return new HostedGame[0]; } [HttpPost] public Guid? HostGame(HostedGameRequest request) { try { var r = this.Request

How to pass products and quantities to ASP.NET MVC4 Web API from form submit

坚强是说给别人听的谎言 提交于 2019-12-25 09:34:13
问题 ASP.NET MVC4 applications allows to enter ordered product quantities and passses them to Web API controller. Controller receives empty product list as product parameter. Debugger shows that data is posted. How to refactor view so that products can passed to Web API ? View: @inherits ViewBase<MyApp.MobileOrderOrderViewModel> <!DOCTYPE html> <html> <body> @using (Html.BeginForm()) { <table> @for (int i = 0; i < Model.Products.Count; i++) { <tr> <td>@Model.Products[i].Id</td> <td> @Html

How to bind a Dictionary from URL query, based on parameter name prefix?

可紊 提交于 2019-12-25 09:19:06
问题 I need to handle http://host.my/path?normal=1&othernormal=2&dict_a=b&dict_x=y Here's my latest attempt at it, based off How to use Bind Prefix? : public string Get(int normal, int othernormal, [Bind(Prefix="dict_")] Dictionary<string, string> dict) { ... } That creates a dictionary, however, it is empty. It is important to note, that dict_a , and dict_x are not known in advance. E.g. dict_abracadabra=bla must be allowed. 回答1: You're able to bind these values to a dictionary without a bind

ng2-file-upload doesn't trigger the controller method .net core web api

不问归期 提交于 2019-12-25 09:13:43
问题 The upload method doesn't trigger a controller method when Content-Type set to 'multipart/form-data'. If Content-Type set to 'application/json' method will triggered but file object will be null. Here is my client(angular 4) implementation: public uploader = new FileUploader({ url: "/api/mycontroller/uploadfile", allowedFileType: ["pdf"], headers: <Headers[]>[ //{ name: 'Content-Type', value: 'application/json' } { name: 'Content-Type', value: 'multipart/form-data' } ] }); save() { //... this

Web API maximum header value length?

删除回忆录丶 提交于 2019-12-25 08:58:31
问题 I've created a Web API project in ASP.Net, and am having some trouble getting the authentication working. The API is expecting a token to be submitted in the Authorization header in each request. The code that checks to see if the header is set checks if the HttpRequestMessage.Headers.Authorization property is null. The first few times I tested this, I discovered that this property was always null, but the strange part is that if you checked the HttpRequestMessage.Headers enumerable, the

The 'ObjectContent`1' type failed to serialize the response body for content type in WebAPI [duplicate]

橙三吉。 提交于 2019-12-25 08:58:04
问题 This question already has answers here : Serialization of Entity Framework objects with One to Many Relationship (2 answers) Closed 4 years ago . I have an MVC5 app, and I have included WebAPI inside it. I tested it and it worked fine for simple string and stuff. Then I tried to do something like this: public Business Get(string id) { return db.Businesses.Where(b => b.Id == id).FirstOrDefault(); } And I got the above mentioned error. Please note that Business is a custom type that I created

WCF REST to web API [closed]

北战南征 提交于 2019-12-25 08:55:55
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I want to migrate from wcf rest services to web API, (around 30 endpoints to be created with 6 complex methods) just want to decide based on the budget (1 month time with one resource) available, which amongst the below would be a better solution. Writing whole new code for

Cross Origin request blocked in Firefox

拜拜、爱过 提交于 2019-12-25 08:55:05
问题 I'm having a problem where by the cross origin requests from my Angular JS application work fine in Chrome but not in Firefox. The error received in firefox is: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.domain.eu/join/joinstatus. (Reason: CORS header 'Access-Control-Allow-Origin' does not match 'https://www.domain.eu, https://www.domain.eu'). I can make requests successfully until I add an Authorization header to the request. My