asp.net-web-api

WebAPI delete list by HttpClient

萝らか妹 提交于 2020-01-04 19:49:33
问题 In my WebApi I want to have method witch accepts ID list as parameter and deletes them all. So this method looks like code below. [HttpDelete] public IHttpActionResult DeleteList([FromBody]IEnumerable<int> templateIds) I also need Unit Test to be written for this using .NET's HttpClient. So my question is: how can I pass array/list of Ids to WebApi using HttpClient DeleteAsync? :) 回答1: As far as I am aware sending a message body in a HTTP DELETE is ignored in Web Api. An alternative is to

Web API return XML

天大地大妈咪最大 提交于 2020-01-04 15:14:39
问题 I'm trying to display the returned data as xml, but it returns in plain text. I've this code: context.Response.AddHeader("Content-Type", "text/xml"); context.Response.Write("<pre>" + HttpUtility.HtmlEncode(writer) + "</pre>"); I'am using this : using (XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, System.Text.Encoding.UTF8)) { ... write the xml } ... and create the XML. This is how I send: context.Response.Write("<pre>" + HttpUtility.HtmlEncode(writer) + "</pre>");

Ninject Property Injection in WebAPI custom ExceptionFilterAttribute Not Working

南笙酒味 提交于 2020-01-04 14:31:13
问题 I am trying to use Ninject to inject an EventLogger instance into a custom ExceptionFilterAttribute. Whenever I run the code, the EventLogger instance is null. I have implemented an IFilterProvider to resolve dependencies in a similar manner for my custom AuthorizationFilterAttribute, and that works fine. Any ideas? Not Working public class ErrorHandlingAttribute : ExceptionFilterAttribute { [Inject] public IEventLogger EventLogger { get; set; } public override void OnException

.NET Web Api - 404 - File or directory not found

狂风中的少年 提交于 2020-01-04 10:36:10
问题 In short words, everything works on local machine but doesn't when deployed to server "A". I'm sure someting is missing in server "A", but I don't know what it is, and I don't have access there to make changes or proper testing. So I'm here to aks for help and ideas of what the problem may be so that I can advise the person in charge of server "A", or whatever changes I need to make on my project to make it work there. That being said, lets talk about my project... I'm using Web Api, and a

Retrieving additional profile information from Facebook during external login/register with ASP.NET Web API 2.0 and Identity

我与影子孤独终老i 提交于 2020-01-04 09:19:29
问题 There appears to be a lot of documentation on how to get additional information from a Facebook profile using ASP.NET Identity and an MVC client, but I can't seem to find anything on how to access the additional info claims from a Web API controller. My Startup.Auth.cs ConfigAuth method contains this, which seems to work alright if I breakpoint on JObject wholeUser = context.User String XmlSchemaString = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims"; var facebookOptions = new

No HTTP resource was found that matches the request URI error in ASP.NET Web API

↘锁芯ラ 提交于 2020-01-04 08:26:33
问题 This is a sketch of my TransferController class. All this is Web API code. public class TransferController : ApiController { [HttpGet, ActionName("Queue")] public IEnumerable<object> GetQueue(Guid sessionId) {...} [HttpDelete, ActionName("Delete")] public void Delete(Guid sessionId, Guid fileId) {...} [HttpGet, ActionName("Cancel")] public bool Cancel(Guid sessionId, Guid fileId) {...} [HttpGet, ActionName("UploadedBytes")] public long GetUploadedByteCount(Guid sessionId, Guid fileId) {...}

How to make a post call to a Web Api Action?

。_饼干妹妹 提交于 2020-01-04 08:08:10
问题 I've created a Web API Action as below [HttpPost] public void Load(string siteName, string providerName, UserDetails userDetails) { // implementation } The route I've registered for this is as below (not sure if it's correct?): config.Routes.MapHttpRoute( name: "loadUserDetails", routeTemplate: "sites/{siteName}/User/Load/{providerName}/{userDetailsList}", defaults: new { controller = "User", action = "Load", providerName = UrlParameter.Optional }); The providerName parameter should be

How to make a post call to a Web Api Action?

和自甴很熟 提交于 2020-01-04 08:08:05
问题 I've created a Web API Action as below [HttpPost] public void Load(string siteName, string providerName, UserDetails userDetails) { // implementation } The route I've registered for this is as below (not sure if it's correct?): config.Routes.MapHttpRoute( name: "loadUserDetails", routeTemplate: "sites/{siteName}/User/Load/{providerName}/{userDetailsList}", defaults: new { controller = "User", action = "Load", providerName = UrlParameter.Optional }); The providerName parameter should be

Node.JS Schema.pre('save) is not changing data

偶尔善良 提交于 2020-01-04 06:26:52
问题 I'm making user authorization system and want to hash password before save it to DB. To reach this i use bcrypt-nodejs. The question in title above; var mongoose = require('mongoose'); var bcrypt = require('bcrypt-nodejs'); var userSchema = new mongoose.Schema({ email: { type: String, unique: true, required: true, }, username: { type: String, unique: true, required: true }, password: { type: String, unique: true, required: true } }); userSchema.pre('save', (next) => { var user = this; bcrypt

Override Message “the value {0} is invalid for {1}” in case of int in WebAPI

耗尽温柔 提交于 2020-01-04 06:12:10
问题 I have a variable name CountryId (Integer Type). If user provides a string or any random input to CountryId , the In-built DefaultBindingModel in ASP.Net throws an error : The value '<script>gghghg</script>' is not valid for CountryId. I want to override this message and provide my own text if the ModelState fails. I want a generic solution. I've searched and tried many solutions, but they only worked for MVC applications, not webAPI . public class IntegerModelBinder : DefaultModelBinder {