asp.net-web-api2


client.DeleteAsync - include object in body

可紊 提交于 2020-02-24 09:17:30
问题 I have an ASP.NET MVC 5 website - in C# client code I am using HttpClient.PutAsJsonAsync(path, myObject) fine to call a Json API (the API is also mine created in Web API). client.BaseAddress = new Uri("http://mydomain"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PutAsJsonAsync("api/something", myObj); I would like to do the same with a Delete verb. However client

MVC Web Api won't allow Windows Authentication

杀马特。学长 韩版系。学妹 提交于 2020-02-14 23:03:31
问题 I have a simple MVC web api 2 IIS hosted application which I want to enable windows authentication (initially not using Owin). I am running this on my development machine and running as local IIS. So, from what I could find, I need to add the following to the web.config 1: to the following section the authentication mode="Windows" <system.web> <compilation debug="true" targetFramework="4.5.1"/> <httpRuntime targetFramework="4.5.1"/> <authentication mode="Windows" /> </system.web> 2: Then add

MVC Web Api won't allow Windows Authentication

独自空忆成欢 提交于 2020-02-14 23:03:30
问题 I have a simple MVC web api 2 IIS hosted application which I want to enable windows authentication (initially not using Owin). I am running this on my development machine and running as local IIS. So, from what I could find, I need to add the following to the web.config 1: to the following section the authentication mode="Windows" <system.web> <compilation debug="true" targetFramework="4.5.1"/> <httpRuntime targetFramework="4.5.1"/> <authentication mode="Windows" /> </system.web> 2: Then add

'TestController.Post()': not all code paths return a value

不羁岁月 提交于 2020-02-05 04:34:07
问题 I am returning HttpResponseMessage , but still my code complains and throw below error, 'TestController.Post()': not all code paths return a value What to return here? public async Task<IHttpActionResult> Post() { var response = await IsDataValid(); if (response) return Ok(new HttpResponseMessage(HttpStatusCode.OK)); } 回答1: You need to add just few more line of code to deal with the above error. public async Task<IHttpActionResult> Post() { var response = await IsDataValid(); if (response)

How can I limit the serving of a javascript file to only authenticated users?

為{幸葍}努か 提交于 2020-01-29 04:56:06
问题 I have a WebAPI 2 / AngularJS SPA application that uses Identity 2 for authentication. Locally my code stores a token for authentication. I would like to implement functionality that allows my application to request additional javascript for authenticated users after my initial index.html page has been downloaded. Is there a way I can make my server code give out the javascript files to only authenticated and authorized users? Something similar to the way a controller action method returns

asp.net mvc web api help page not populating for given route

柔情痞子 提交于 2020-01-26 01:41:37
问题 I am having difficulties having the help page populate for a web api controller. The only method in the controller is the following: public HttpResponseMessage Get(string p1,string p2= "blend", string p3 = "blend") The method appears reflected in the help page with the signature: GET api/mycontroller?p1={p1}&p2={p2}&p3={p3} However none of my comments flow to the help page. For other simple controller Get(string id) the help page works ok. I tried adding the following on the WebApiConfig.cs

Doesn't ASP.NET Web Api Model Binding Use Newtonsoft (JSON.NET)

本小妞迷上赌 提交于 2020-01-26 00:59:46
问题 As far as I understand, Web Api uses Newtonsoft (JSON.NET) serializer/deserializer when model binding. But when I use [JsonProperty(Required = Required.AllowNull)] attribute for a model property, it does not work. I omit the property in JSON but model binder does not throw exception or make the ModelState.IsValid false. My questions are: Why does it not work if Web Api is using Json.Net? Is there a simple solution like a configuration change? If I have to use a custom model binder in order to

Angular 2 Can’t get data from Rest Service

别来无恙 提交于 2020-01-25 21:10:39
问题 I’m new in Angular 2 and I’m playing with the environment to create some app. Doing the things like the site Angular.io says I’m able to create an Injectable Service and using it on my AppComponent but only If I read the data from the same .ts file like this.sourceData = {…}. If I get the json data from a Rest service the data is undefined app.service.ts Import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { Headers, RequestOptions } from '

Angular 2 Can’t get data from Rest Service

梦想的初衷 提交于 2020-01-25 21:10:34
问题 I’m new in Angular 2 and I’m playing with the environment to create some app. Doing the things like the site Angular.io says I’m able to create an Injectable Service and using it on my AppComponent but only If I read the data from the same .ts file like this.sourceData = {…}. If I get the json data from a Rest service the data is undefined app.service.ts Import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { Headers, RequestOptions } from '

Angular 2 - download csv file

徘徊边缘 提交于 2020-01-25 09:32:08
问题 I'm trying to download a csv file from a Microsoft Web API 2 controller. Here's what I have so far:- Web API:- [Route("extractContent/{extractId}")] public async Task<IHttpActionResult> GetExtractContent(int extractId) { _logger.Info($"Getting extract file content for extract with id: {extractId}..."); try { IEnumerable<ExtractDto> extracts = await _extractService.GetExtractsAsync(new ExtractSearchRequest { ExtractId = extractId }); ExtractDto extract = extracts?.FirstOrDefault(); if (extract

工具导航Map