asp.net-web-api2

Angular download csv file with Web Api 2

放肆的年华 提交于 2019-12-06 08:18:34
I am trying to download a csv file using web api 2 and angular js. This is my controller code public IHttpActionResult ExportCsvData() { var stream = new FileStream("Testcsv.csv", FileMode.Open, FileAccess.Read); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(stream); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "Testcsv.csv" }; return Ok(response); } This is my angular code, var filename =

Token based authentication for both Web App and Web API using Azure AD B2C

萝らか妹 提交于 2019-12-06 08:15:12
Scenario: Both Web application and Web API need to be authenticated and protected from the server side. Requirement: Web application is serving the contents for the browser and browser should be calling Web API directly (i.e. Browser to API). Question: Is it possible to authenticate both Web APP and the API using tokens? Any sample code or clear direction would be highly appreciated. Normally web applications are authenticated using cookies and APIs are authenticated using tokens.There are some sample projects available here but they are either browser to API (SPA token based) or Server side

Testing the Patch odata webapi method

↘锁芯ラ 提交于 2019-12-06 07:05:43
问题 I need to test the following Patch method in my odata controller from my test project. [ValidateModel] [AcceptVerbs("PATCH", "MERGE")] public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<User> patch) { var user = await db.Users.FindAsync(key); if (user == null) { return NotFound(); } patch.Patch(user); Validate(user); if (!ModelState.IsValid) { return BadRequest(ModelState); } try { db.Entry(user).Property(p => p.UserType).IsModified = false; await db.SaveChangesAsync();

Issue with inheritance with WebAPI, OData v3 and BreezeJs

你离开我真会死。 提交于 2019-12-06 07:03:18
We are using WebAPI 2.2, with OData v3 and BreezeJS and are having an issue when using inheritance, we have a setup along the following lines (simplified obviously for this issue) We have a Vehicle abstract class and then two other classes (Bus and Car) which inherit from Vehicle, such as: public abstract class Vehicle { public int Id { get; set; } public string Name { get; set; } } public class Bus : Vehicle { public int NumberOfSeats { get; set; } } public class Car : Vehicle { public string Colour { get; set; } } We then have an Activity class which can have a single Vehicle (either a Car

Large File download from SQL via WebApi after custom MultipartFormDataStreamProvider upload

旧时模样 提交于 2019-12-06 06:18:14
This is a follow up to a question I had asked previously that was closed for being too broad. Previous Question In that question I explained that I needed upload a large file (1-3GB) to the database by storing chunks as individual rows. I did this by overriding the MultipartFormDataStreamProvider.GetStream method. That method returned a custom stream that wrote the buffered chunks to the database. The problem is that the overriden GetStream method is writing the entire request to the database (including the headers). It is successfully writing that data while keeping the Memory levels flat but

Best way to convert Asp.Net MVC controllers to Web API

寵の児 提交于 2019-12-06 06:15:06
I have this ASP.NET MVC 5 project which I'm converting over to AngularJS with MS Web Api. Now in the old project I have these c# controllers of type Controller , however in my new project I've created some new Web Api controllers of type ApiController . Now I'd like to reuse the old controller code in my new project. Herein lies my confusion. As I attempt to port the old controller code over to my Web Api controller, I'm getting some front-end $http request errors. Here's a function from my Angular dataService factory which makes an http req down to 'api/Whatif/SummaryPortfolios' : function

Autofac WebApi 2 OWIN Not Working

╄→гoц情女王★ 提交于 2019-12-06 06:10:10
Having an issue with Autofac and WebApi2 using OWIN. Basically the Constructor isn't getting Injected. public class Startup { public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "Default Route", routeTemplate: "{controller}.{ext}" ); config.Routes.MapHttpRoute( name: "Default Route with Id", routeTemplate: "{controller}/{id}.{ext}", defaults: new { id = RouteParameter.Optional } ); var builder = new ContainerBuilder(); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder

Using Unity with Web Api 2 gives error does not have a default constructor

好久不见. 提交于 2019-12-06 06:09:34
I have ASP.NET MVC5 web application and i also have Web API in the same application. I am uisng Unity (version 4) for DI. I am configuring the Unity container on APP start as below public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { UnityConfiguration.Config(); } } public class UnityConfiguration() { public void Config() { UnityContainer container = new UnityContainer(); container.RegisterType<IMyService, Myservice>(); container.RegisterType<IGenericRepository, GenericRepository>(); container.RegisterType<DbContext, MyEntities>(); } } public class

UserManager dependency injection with Owin and Simple Injector

↘锁芯ラ 提交于 2019-12-06 05:42:12
After adding Simple Injector to my project to create an instance of my UserAppManager that will exist through the whole lifetime of a session I started to recieve errors: Error with no parameterless constructor: An error occurred when trying to create a controller of type 'AuthController'. Make sure that the controller has a parameterless public constructor. Error with a parameterless constructor: For the container to be able to create AuthController it should have only one public constructor: it has 2. I followed a guide ( https://simpleinjector.codeplex.com/discussions/564822 ) to avoid

JSON to Model property binding using JsonProperty

家住魔仙堡 提交于 2019-12-06 04:37:51
问题 I'm bound by agreements between my party and the client to use json parameters containing dashes. Since it's not possible to use that in property names in C#, I need to map to the desired property. What I do now: The below code is simplified for convenience. Model public class MyRequest { [JsonProperty("request-number")] public string RequestNumber { get; set; } [JsonProperty("name")] public string Name { get; set; } } Controller [HttpGet] [Route("api/load-stuff")] public Stuff LoadStuff(