asp.net-web-api

How to change default Web API 2 to JSON formatter?

回眸只為那壹抹淺笑 提交于 2020-01-09 12:51:29
问题 I have a Web API project that returns some product data. It negotiates the return type correctly depending on the Accept header (JSON/XML) of the request. The problem is, if no Accept header is specified it returns XML, but I want it to return JSON by default http://website.com/MyPage?type=json // returns json http://website.com/MyPage?type=xml // returns xml http://website.com/MyPage // returns xml by default Here is my current code looks like: GlobalConfiguration.Configuration.Formatters

Ember-Data: How do “mappings” work

本小妞迷上赌 提交于 2020-01-09 09:10:15
问题 I'm currently trying to put something together with ember + emberdata + router + asp.net web api. Most of it seem to work, however I stuck in an error message I get when ember-data tries to findAll through the adapter for my models. In my backend I have a model like this (C#): public class Genre { [Key] public int Id { get; set; } [Required] [StringLength(50, MinimumLength=3)] public string Name { get; set; } } Which in my app I represent it like this using ember-data: App.Genre = DS.Model

Ember-Data: How do “mappings” work

妖精的绣舞 提交于 2020-01-09 09:10:12
问题 I'm currently trying to put something together with ember + emberdata + router + asp.net web api. Most of it seem to work, however I stuck in an error message I get when ember-data tries to findAll through the adapter for my models. In my backend I have a model like this (C#): public class Genre { [Key] public int Id { get; set; } [Required] [StringLength(50, MinimumLength=3)] public string Name { get; set; } } Which in my app I represent it like this using ember-data: App.Genre = DS.Model

ASP.NET Identity in Microservice Architecture

浪尽此生 提交于 2020-01-09 03:21:45
问题 I'm attempting to implement a web app using a microservice architecture by breaking up major components into separate web servers. I'm implementing an authentication server using ASP.NET Identity (email/username logins only, no Facebook, etc) and a "main" application server. My current challenge is figuring out how the application server will recognize if a user has logged via the authentication server. Since the authentication server generates tokens which it users to verify users's

anchor inline text with image

梦想的初衷 提交于 2020-01-07 05:31:09
问题 i am trying to add a image with the option inline with text, i already am able to place floating images around text, but i want to give the option to put them inline with text, as i read the docs it says that i can't use the wrap mode for the inline option. My daubt is how can i set the anchor element to inline without changing all my function? at the moment i have this: private static Drawing DrawingManager(string relationshipId, string name, int cxVal, int cyVal, string impPosition, String

Reading the web.config file from Global.asax

心不动则不痛 提交于 2020-01-07 04:22:09
问题 I have start up code in my Web API project that attempts to read values from the web.config file which is published inside the bin directory by default. Because the application initialization point is Global.asax, there is no web.config at this level so I need to figure out how to reference it down in the bin folder. Here is the root of my IIS directory: Anytime I try to read values from the web.config file using ConfigurationManager.AppSettings they come back null. It's only when I move the

C# .net UriTemplate match url from a whitelist or pool or servers

↘锁芯ラ 提交于 2020-01-07 03:42:16
问题 You can use UriTemplate to parse the url: I have this code in which locally on localhost:29001 I set the host to be a specific Uri and then I check to if it is a Match In my real code I do have the the line var absoluteUri = HttpContext.Current.Request.Url.AbsoluteUri; of which is used like this var match = apiTemplate.Match(host, new Uri(absoluteUri)); but essentially this is what the code is going to look like in C# from it running. var host = new Uri("http://localhost:29001"); var

HttpClient ReadAsAsync<Type> only deserializing part of the response

谁说我不能喝 提交于 2020-01-07 03:27:09
问题 I am using the following to make a call to a WebAPI using (HttpClient client = HttpClientFactory.Create(new AuthorisationHandler())) { client.BaseAddress = new Uri(BaseURI); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml")); var httpResponseMessage = await client.PostAsXmlAsync<AvailRequest>("Avail/Search/", req); httpResponseMessage.EnsureSuccessStatusCode(); var availResp =

Why I cannot use HttpResponseMessage class?

a 夏天 提交于 2020-01-07 03:26:07
问题 I'm new to ASP.NET Web API and want to make HttpResponseMessage instance from a utility class I made. Then I made very simple class. But following compile error occurred. CS0246: The type or namespace name 'HttpResponseMessage' could not be found (are you missing a using directive or an assembly reference?) using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Web; namespace myapplication.App_Code.Utils { public class HttpUtility { // compile

NetworkError: Failed to execute 'send' on 'XMLHttpRequest' (ajax、WebAPI)

人走茶凉 提交于 2020-01-07 03:11:47
问题 I'm trying to do a POST ajax request to C# WebAPI, but I can't seem to get any information back. When I click a button on my site, I can see the server passing back the this error: "NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://120.96.86.139/api/SingleLoginPOST/'." I already Add Header: <meta http-equiv="Access-Control-Allow-Origin" content="*" /> <meta http-equiv="Access-Control-Allow-Headers" content="Content-Type" /> <meta http-equiv="Access-Control