webapi

WebApi OAuth UseOAuthBearerAuthentication gives “Sequence contains more than one element” error

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I configured my WebApi OAuth 2.0 by these lines: app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions { Provider = new OAuthBearerAuthenticationProvider(), }); app.UseOAuthBearerTokens(OAuthOptions); But it gives me the following error at each request : Message : An error has occurred. ExceptionMessage : Sequence contains more than one element ExceptionType : System.InvalidOperationException StackTrace : at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) at Microsoft.Owin.Security.AuthenticationManager

WebAPI + APIController with structureMap

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Im trying to use StructureMap to initialize my ValuesController that derivate from ApiController but i'm getting an exception that says: The IControllerFactory '...CustomControllerFactory' did not return a controller for the name 'api'. Here is the code.. public class CustomControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { if (controllerType == null) return null; return (Controller)ConcretizationsManager.GetInstance(controllerType); } }

.Net Core WebAPI connection reset, when I have “include” in my controller

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a new project with .Net Core. It's a WebAPI project. And I have a separate project for my model. In WebAPI project, in a controller, I have something like this: // GET: api/questions [HttpGet] public IEnumerable<Question> GetQuestions() { return _context.Questions .Include( i => i.QuestionType ); } When I call http://localhost:55555/api/questios/ it just returns the first record, and then this error message: Recv failure: Connection was reset If I remove the Include part and just return the _context.Questions , it work just fine! What

ASP.NET Core WebAPI 500 Internal error in IIS 7.5

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm struggling to get this WebAPI to work. Well, work with IIS. Everything works fine in IIS express, but when I publish it, specifically 1 api request doesn't work. I'm trying to access a url of API/[Controller]/{date}/{integer} . I keep getting the 500 server error. My other route of API/[Controller]/{date} works. Here's my API Controller: [Route("api/[controller]")] public class PostingsController : Controller { // GET: api/Postings/5 [HttpGet("{date}")] public string Get(string date) { return date; } // GET api/Postings/20160407/2

Make WebAPI actions async?

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a question about whether it's beneficial to use async/await on WebAPI / MVC Controller AJAX requests. Say I've got this AngularJS app that talks to a WebAPI backend and I want to get some data. I do some AJAX call to WebAPI and wait for the results. In terms of the client, this is of course Async. Would it now be beneficial for the server if I was to make these actions Async? EDIT I just found this: http://www.dotnetcurry.com/showarticle.aspx?ID=948 - saying it IS EDIT - attempt to clarify Let me try to be more clear. Will the

ASP.NET WebApi: how to perform a multipart post with file upload using WebApi HttpClient

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a WebApi service handling an upload from a simple form, like this one: However, I can't figure out how to simulate the same post using the HttpClient API. The FormUrlEncodedContent bit is simple enough, but how do I add the file contents with the name to the post? 回答1: After much trial and error, here's code that actually works: using (var client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { var values = new[] { new KeyValuePair ("Foo", "Bar"), new KeyValuePair ("More", "Less"), }; foreach (var

NEST2 initialization on .NET C# WebAPI

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I defined the NEST2 client dependencies like this: container.RegisterType<IElasticClient, ElasticClient>( new InjectionConstructor( new ResolvedParameter<IConnectionSettingsValues>(), new OptionalParameter<IConnection>(), new OptionalParameter<IElasticsearchSerializer>(), new OptionalParameter<ITransport>())); I was using NEST and ElasticSearch. Now I moved to NEST 2 and ElasticSearch 2 and I had to change INestSerializer into IElasticsearchSerializer Unfortunately now I've got this error on ITransport Using the generic type ITransport

WebAPI Custom Model binding of complex abstract object

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This is a tough one. I have an issue with binding a model from JSON. I am attempting to resolve polymorphic-ally the record supplied with the type of record that it will resolve to (I want to be able to add many record types in the future). I have attempted to use the following example to resolve my model when calling the endpoint however this example only works for MVC and not Web API applications. I have attempted to write it using IModelBinder and BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext).

ASP.NET WebApi : (405) Method Not Allowed

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Web Api controller. It behaves very strange. When I use PostMan I can access the POST method on the Web Api but when I use HttpWebRequest from .net it returns (405) Method Not Allowed. I put the Web Api code here: using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http; namespace MyProject.Controllers { public class TestController : ApiController { [HttpPost] public int buy(OrderResult value) { try { if (value

OAuth2 WebApi Token Expiration

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to set a token expiration time dynamically, but it appears it just keeps defaulting to 20 minutes. Here is my ConfigureAuth: public void ConfigureAuth(IAppBuilder app) { OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(""), // In production mode set AllowInsecureHttp = false AllowInsecureHttp = true }; // Enable the application to use bearer tokens to authenticate users app.UseOAuthBearerTokens(OAuthOptions); } Here is my