asp.net-web-api2

Is it possible to set the Default Content-Type to “application/json;v=2.0”

半城伤御伤魂 提交于 2020-01-04 07:30:48
问题 Is it possible to set the Default Content-Type to "application/json;v=2.0". I say default because I'm using a HttpClient class and I use the DefaultRequestHeaders to set my proxies default values. I followed this example to create my headers https://stackoverflow.com/a/10679340/196526 but I also use versioning and information about versioning is saved in ContenT-Type public class BankAccountProxy { public void SetToken() { Client = new HttpClient(); Client.BaseAddress = new Uri(System

How do I prevent the creation of multiple background processes working on the same request?

China☆狼群 提交于 2020-01-04 06:58:44
问题 I have a simple WebApi controller method that's purpose is to trigger some background processing and return a 202 Accepted response immediately (without necessarily having completed the background processing as is consistent with a 202 response.) public async Task<IHttpActionResult> DoSomething(string id) { HostingEnvironment.QueueBackgroundWorkItem(async ct => { //Do work } return ResponseMessage(new HttpResponseMessage(HttpStatusCode.Accepted)); } However, I want to be able to prevent

Need help debugging JwtSecurityTokenHandler (web api owin auth / resource servers)

我怕爱的太早我们不能终老 提交于 2020-01-04 06:56:09
问题 I am desperately trying to find out why I keep getting a 401 response from my resource server: Scenario: Console program running an authorization server. Console program running a resource server. Console program using both (client). I have no problem getting the token, and it validates with expected content at jwt.io. Further, when submitting the base64 encoded secret used to create the token, the site also validates the token string. I have tried every possible combination of suppressing

Async await usage and overhead [closed]

元气小坏坏 提交于 2020-01-04 06:53:28
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I have a web api 2 endpoint that talks to a service class. The service class makes calls to Entity Framework (v6) I have applied async await on the methods where im writing to the database, querying etc.. using SaveChangesAsync(), etc My question is regarding the overhead.. the

Async await usage and overhead [closed]

余生长醉 提交于 2020-01-04 06:53:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I have a web api 2 endpoint that talks to a service class. The service class makes calls to Entity Framework (v6) I have applied async await on the methods where im writing to the database, querying etc.. using SaveChangesAsync(), etc My question is regarding the overhead.. the

multi databases with own identity tables should connect with single web api and validate jwt token

江枫思渺然 提交于 2020-01-04 06:05:29
问题 i am working on a project which is same for several companies, so we have created different databases for different companies with same db structure, each db has it's own identity tables, roles based menus, role based access permission. I have written a single api to connect different databases based on username supplied. as all company logins with same login screen. we decide which db to connect by username passed on loginscreen. Example : 3 companies- abc.com,pqr.com,xyz.com single login

C# web api route for a webservice

こ雲淡風輕ζ 提交于 2020-01-04 05:49:08
问题 I am coding a web api in c# and I have a question in regards to the correct route to access a function called test . Here is the class definition: [RoutePrefix("api")] public class ItemsWebApiController : ApiController I have a RoutePrefix as follows: [Route("test")] Here is the function called test : [Route("test")] [System.Web.Http.AcceptVerbs("GET")] [System.Web.Http.HttpGet] public String test() { return "test"; } I am trying to access the following url: http://localhost/api/test The

Web API action not found when optional parameter not present in URL

℡╲_俬逩灬. 提交于 2020-01-04 02:48:10
问题 please help. I had to change routing for Web API to be able to use methods in URL: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // for MVC controllers routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Editions", action = "Index", id = UrlParameter.Optional } ); // for Web API routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/

AS.NET WEB API Global Exception Handler Cannot Access Request Content

与世无争的帅哥 提交于 2020-01-03 20:57:27
问题 I'm trying to log information about the request that has caused an exception. I'm trying to read the Content of the request attached to the ExceptionHandlerContext below :- Although I can access other parts of the request object, its content is always empty. It seems by this point in the pipeline it has been disposed. Is there a way to capture the request body this far up the stack? public class GlobalExceptionHandler : ExceptionHandler { public override void Handle(ExceptionHandlerContext

Correct way to use Serilog with WebApi2

末鹿安然 提交于 2020-01-03 18:02:29
问题 I am in search of the correct way to use serilog with aspnet webapi2. As for now I initialize the global Log.Logger property like that : public static void Register(HttpConfiguration config) { Log.Logger = new LoggerConfiguration() .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200")) { IndexFormat = IndexFormat, BufferBaseFilename = outputLogPath, AutoRegisterTemplate = true, AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6, CustomFormatter = new