asp.net-web-api2

Web api passing array of integers to action method

拥有回忆 提交于 2019-12-01 13:23:39
I have this web api method: [HttpGet] [Route("WorkPlanList/{clientsId}/{date:datetime}")] public async Task<IHttpActionResult> WorkPlanList([FromUri]List<int> clientsId, [FromUri]DateTime date) { } Here is URI that I use to call the action method above: http://localhost/blabla/api/workPlan/WorkPlanList/5,4/2016-06-01 I set the break point on curved bracket and see date time value is passed perfect while clientsId value is 0 . Any idea why I get 0 on clientsId ? Your problem intrigued me so I wanted to come up with a solution that was a bit more generic than the answer Nkosi provided. While

To send get request to Web API from Java Servlet

江枫思渺然 提交于 2019-12-01 13:13:58
问题 Common question Is is possible to send get reguest from Java servlet's doGet method ? I need to check some "ticket" against my Web API .NET service, so can I call to this service from my custom servlet in the doGet method ? public class IdentityProviderServlet extends HttpServlet { ... @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { ... // make request to Web API and save received user name to response ... } Details We have web-app (

Attribute vs Conventional Routing

我们两清 提交于 2019-12-01 11:39:25
Q1: So this article says attribute routing is more favourable than conventional routing for api versioning. It's not clear to me the reasons behind such claim because to me in order to support these: /api/v1/products /api/v2/products all you need to do is to define two routes: routes.MapHttpRoute("V1", "api/v1/products", new {controller = "V1Controller", action = "ListProducts"}); routes.MapHttpRoute("V2", "api/v2/products", new {controller = "V2Controller", action = "ListProducts"}); Can something share some insight? Q2: this article says one issue with conventional routing is the order of

ServicePointManager.DefaultConnectionLimit returning Int32.MaxValue

拟墨画扇 提交于 2019-12-01 11:21:02
For diagnostics purposes I am logging ServicePointManager.DefaultConnectionLimit. However oddly enough it seems to be returning Int32.MaxValue (i.e 2147483647). This seem to contradict the MSDN documentation on the subject: The maximum number of concurrent connections allowed by a ServicePoint object. The default value is 2. For context, I am getting this value in an ASP.Net 4 application running on 4.6.1 Oliver Based on @Wimmel's link it seems in ASP.Net that it is set to Int32.MaxValue as part of the HTTP Runtime. We can see this by looking inside the System.Web assembly at the HttpRuntime

Error 401 Unauthorized. How to Use the same token for different Urls?

谁说我不能喝 提交于 2019-12-01 10:50:15
In ASP.Net Identity using Oauth2 a token is created once the user is authenticated posting User and Password. Before making a call to an action from one API, the user must ask for a token: http://mysite/auth/token Once the token is received, all Web Api calls can be done, sending the Authorization: Bearer <token> header: GET http://mysite/auth/product/1 PUT http://mysite/auth/client/42 I have several Web Apis that use a centralised Security System for Authentication, the problem is that I receive Unauthorizaed (401) when I try to call different Api (with different URL). For example: GET http:/

Attribute vs Conventional Routing

▼魔方 西西 提交于 2019-12-01 09:38:43
问题 Q1: So this article says attribute routing is more favourable than conventional routing for api versioning. It's not clear to me the reasons behind such claim because to me in order to support these: /api/v1/products /api/v2/products all you need to do is to define two routes: routes.MapHttpRoute("V1", "api/v1/products", new {controller = "V1Controller", action = "ListProducts"}); routes.MapHttpRoute("V2", "api/v2/products", new {controller = "V2Controller", action = "ListProducts"}); Can

Get the IP address of the client connecting to a C# .NET WebAPI application

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 07:35:59
I tried: private const string HttpContext = "MS_HttpContext"; private const string RemoteEndpointMessage = "System.ServiceModel.Channels.RemoteEndpointMessageProperty"; public static string GetClientIpAddress(HttpRequestMessage request) { if (request.Properties.ContainsKey(HttpContext)) { dynamic ctx = request.Properties[HttpContext]; if (ctx != null) { return ctx.Request.UserHostAddress; } } if (request.Properties.ContainsKey(RemoteEndpointMessage)) { dynamic remoteEndpoint = request.Properties[RemoteEndpointMessage]; if (remoteEndpoint != null) { return remoteEndpoint.Address; } } return

asp.net web api 2 CORS and authentication authorization configuration

情到浓时终转凉″ 提交于 2019-12-01 05:57:37
I've created an asp.net web api 2 service with individual account security. I'm trying to call it form AngularJs as per this example: http://www.codeproject.com/Articles/742532/Using-Web-API-Individual-User-Account-plus-CORS-En could not get that to work so added some config from here: How to make CORS Authentication in WebAPI 2? and can't get past this error: XMLHttpRequest cannot load 'serverRegisterUrl'. The 'Access-Control-Allow-Origin' header contains multiple values 'clientUrl, *, *', but only one is allowed. Origin 'clientUrl' is therefore not allowed access. I don't understand this

Setting Result in the context of ChallengeAsync method in an authentication filter

人走茶凉 提交于 2019-12-01 05:35:27
This question is related to the answer I have provided here . OP's comment got me thinking a bit. I suggested using a class implementing IHttpActionResult like this in the ChallengeAsync method of the authentication filter. public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken) { context.Result = new ResultWithChallenge(context.Result); return Task.FromResult(0); } public class ResultWithChallenge : IHttpActionResult { private readonly IHttpActionResult next; public ResultWithChallenge(IHttpActionResult next) { this.next = next; } public

Anatomy of an OWIN Startup

我们两清 提交于 2019-12-01 04:41:05
What are all the hooks on the OWIN Startup class? Information on these is scarce. For example, one required hook on every Startup class is that it should have a Configuration method. This information can be gathered from the Microsoft documentation . class Startup { public void Configuration(IAppBuilder appBuilder) { ... } } What is the rationale behind not having an IOwinStartup interface or OwinStartup base class in the framework? interface IOwinStartup { void Configuration(IAppBuilder appBuilder); } How do I perform cleanup for my OWIN-based application? Does OWIN detect a Dispose method on