asp.net-web-api2

CORS: credentials mode is 'include'

坚强是说给别人听的谎言 提交于 2019-11-30 06:13:02
问题 Yes, I know what you are thinking - yet another CORS question, but this time I'm stumped. So to start off, the actual error message: XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include' . Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the

Web API self host - bind on all network interfaces

青春壹個敷衍的年華 提交于 2019-11-30 05:55:28
How do you make a Web API self host bind on all network interfaces? I have the below code currently. Unfortunately, it binds only on localhost. So access to this server from other than localhost is failing. var baseAddress = string.Format("http://localhost:9000/"); using (WebApp.Start<Startup> (baseAddress)) { Console.WriteLine("Server started"); Thread.Sleep(1000000); } Just change the base address like this var baseAddress = string.Format("http://*:9000/"); using (WebApp.Start<Startup> (baseAddress)) { Console.WriteLine("Server started"); Thread.Sleep(1000000); } And it should bind

Web API 2 download file using async Task<IHttpActionResult>

给你一囗甜甜゛ 提交于 2019-11-30 03:44:44
I need to write a method like below to return a text document (.txt, pdf, .doc, .docx etc) While there are good examples of posting file in Web API 2.0 on the web , I couldn't find a relevant one for just downloading one. (I know how to do it in HttpResponseMessage.) public async Task<IHttpActionResult> GetFileAsync(int FileId) { //just returning file part (no other logic needed) } Does the above needs to be async at all? I am only looking to return stream. (Is that okay?) More importantly before I end up doing the job one way or the otther, I wanted to know what's the "right" way of doing

Referencing Action Parameters from ExceptionLogger

只谈情不闲聊 提交于 2019-11-30 03:33:19
问题 I'm wanting to make use of the new method for globally logging errors. I've written a class that inherits ExceptionLogger and overrides the Log() method. Then registered it as a replacement. public class TraceExceptionLogger : ExceptionLogger { public async override void Log(ExceptionLoggerContext context) { // This is always empty string var content = await context.Request.Content.ReadAsStringAsync(); // This is almost always null var actionContext = context.ExceptionContext.ActionContext; }

Web API with OWIN throws ObjectDisposedException for HttpMessageInvoker

北慕城南 提交于 2019-11-30 03:19:01
问题 I am having some difficulties with OWIN in a ASP.NET WebApi2 setting. The first request after a restart results in the exception: [ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpMessageInvoker'.] System.Net.Http.HttpMessageInvoker.CheckDisposed() +327456 System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +24 System.Web.Http.Owin.<InvokeCore>d__0.MoveNext() +501 System.Runtime

Web Api 2 Preflight CORS request for Bearer Token

╄→尐↘猪︶ㄣ 提交于 2019-11-30 01:54:08
I have a web-app with an AngularJS front-end and a Web Api 2 back-end, and it uses bearer-tokens for authentication. All is well in FireFox & IE, but with Chrome, my initial login request is SOMETIMES pre-flighted. Here's the call from the AngularJS service: $http.post( http://localhost:55483/token , data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).success(function (response) { ... }); The preflight request gets kicked back with an "Allow-Access-Control-Origin" error. However, if I click the Login button again (thereby re-sending the above request) all is well. Any

Load JSON string to HttpRequestMessage

爷,独闯天下 提交于 2019-11-30 01:33:22
问题 I'm writing some tests for my WebAPI web service and cannot figure out how to send JSON to my service method in the test. ScheduleRequest sr = new ScheduleRequest(); sr.Months = null; sr.States = null; sr.Zip = null; sr.Miles = null; sr.PCodes = null; sr.PageStart = 1; sr.PageLimit = 10; HttpRequestMessage m = new HttpRequestMessage(); string sr_ = JsonConvert.SerializeObject(sr); // How do I load it into the HttpRequestMessage??? // m.Content. = sr_; var controller = new

An assembly specified in the application dependencies manifest (…) was not found

丶灬走出姿态 提交于 2019-11-30 00:37:49
I upgraded Microsoft.AspNetCore from 2.0.3 to 2.0.5 and my WebAPI project, although running successfully locally, fails to start in production (IIS). Everything was fine in production until this upgrade. The error message produced in the log directory is as follows: Error: An assembly specified in the application dependencies manifest (MyProject.WebAPI.deps.json) was not found: package: 'Microsoft.AspNetCore.Mvc.Abstractions', version: '2.0.2' path: 'lib/netstandard2.0/Microsoft.AspNetCore.Mvc.Abstractions.dll' This assembly was expected to be in the local runtime store as the application was

Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)

吃可爱长大的小学妹 提交于 2019-11-30 00:26:10
问题 I have a Web API 2 project with help pages that runs fine locally but throws this error when I push it to Azure: Method not found: 'System.String System.String.Format (System.IFormatProvider, System.String, System.Object) I temporarily turned custom errors off so full stack trace can be seen here The error is originating from this line of code: string selectExpression = String.Format(CultureInfo.InvariantCulture, MethodExpression, GetMemberName(reflectedActionDescriptor.MethodInfo)); See Line

How to use Swagger as Welcome Page of IAppBuilder in WebAPI

允我心安 提交于 2019-11-29 23:59:40
I try to use Swagger with Microsoft WebAPI 2. For the moment, I've the following call in a method. appBuilder .ConfigureOAuth() .UseWebApi(configuration) .UseWelcomePage(); If I want to use Swagger, I must use this url " https://localhost:44300/swagger " which one works very well. I want my home page redirects to the url of my swagger, perhaps as follows but this sample doesn't works. appBuilder ... .UseWelcomePage("/swagger"); Any idea ? I got this working how I wanted by adding a route in RouteConfig.cs like so: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("