asp.net-web-api

ASP.Net WebAPI Return value for PDF Form Submit

寵の児 提交于 2020-03-05 07:05:44
问题 How do I get my Asp.net webapi to return the correct response for a pdf form submit? 回答1: To keep the response inside of the pdf application you must return an FDF formatted file. The key to get this to work is that you cannot just return a string. You must first encode it to a memory stream and the header must be set to application/vnd.fdf . Here is the example code: Public Function PostValue(<FromBody()> ByVal value As MyPDFFieldsObject) As HttpResponseMessage Dim fdfmessage As String = "

ASP.Net WebAPI Return value for PDF Form Submit

最后都变了- 提交于 2020-03-05 07:04:01
问题 How do I get my Asp.net webapi to return the correct response for a pdf form submit? 回答1: To keep the response inside of the pdf application you must return an FDF formatted file. The key to get this to work is that you cannot just return a string. You must first encode it to a memory stream and the header must be set to application/vnd.fdf . Here is the example code: Public Function PostValue(<FromBody()> ByVal value As MyPDFFieldsObject) As HttpResponseMessage Dim fdfmessage As String = "

Route parameters and multiple controller types

安稳与你 提交于 2020-03-01 20:59:11
问题 I have a asp.net web api, using attributes for routing on the controllers. There are no route attriutes on the action level. The route for accessing a resource is: [Route("{id}"] public MyApiController: ApiController { public HttpResponseMessage Get(Guid id) { // ... } } My problem is that when I want to create a search controller, I'd like the URL to be [Route("search")] But this results in an error: Multiple controller types were found that match the URL . Is it possible to make sure the

Route parameters and multiple controller types

别说谁变了你拦得住时间么 提交于 2020-03-01 20:58:32
问题 I have a asp.net web api, using attributes for routing on the controllers. There are no route attriutes on the action level. The route for accessing a resource is: [Route("{id}"] public MyApiController: ApiController { public HttpResponseMessage Get(Guid id) { // ... } } My problem is that when I want to create a search controller, I'd like the URL to be [Route("search")] But this results in an error: Multiple controller types were found that match the URL . Is it possible to make sure the

Should I HTML encode response of my Web API

て烟熏妆下的殇ゞ 提交于 2020-02-29 17:07:49
问题 I am designing a Web API which returns JSON as the content-type, the response body could contain characters like ' , " , < and > , they are valid characters in JSON. So, my question is should I do HTML encode for my Web API response body or should I leave this task to HTML client who is consuming my Web API? 回答1: No; you must not. You must only escape data if and when you concatenate it into a structured format. If you return JSON like { "text": "Content by X & Y" } , anyone who reads that

Should I HTML encode response of my Web API

对着背影说爱祢 提交于 2020-02-29 17:07:04
问题 I am designing a Web API which returns JSON as the content-type, the response body could contain characters like ' , " , < and > , they are valid characters in JSON. So, my question is should I do HTML encode for my Web API response body or should I leave this task to HTML client who is consuming my Web API? 回答1: No; you must not. You must only escape data if and when you concatenate it into a structured format. If you return JSON like { "text": "Content by X & Y" } , anyone who reads that

WebApi async vs sync

為{幸葍}努か 提交于 2020-02-28 23:37:32
问题 I'm new to .Net WebApi, as I know it's preferable to use async APIs instead of sync ones, but what is the difference? if the API is sync and has been called from a client, and another call from another client, as I checked, no interruption will happen, and both calls will go through simultaneously. So, what's the benefit of making it Async? Update: as I understand, if the number of requests are huge, if I use async, the waiting time for some calls will be less, cause there are more threads

ASP.NET Web API returns NULL for object when using XML

久未见 提交于 2020-02-25 05:39:27
问题 I've tried to follow the instructions I found, but still it does not work. I have following class public class TodoItem { public int Id { get; set; } public string Name { get; set; } public bool IsComplete { get; set; } public TodoItem() { } } My server has following POST Method public IHttpActionResult Post([FromBody]TodoItem item) { if (item != null) { TodoRepository.Current.Add(item); return Ok(item); } return BadRequest("Object is null"); } In my WebApiConfig.cs I have added following

ASP.NET Web API returns NULL for object when using XML

ぐ巨炮叔叔 提交于 2020-02-25 05:38:06
问题 I've tried to follow the instructions I found, but still it does not work. I have following class public class TodoItem { public int Id { get; set; } public string Name { get; set; } public bool IsComplete { get; set; } public TodoItem() { } } My server has following POST Method public IHttpActionResult Post([FromBody]TodoItem item) { if (item != null) { TodoRepository.Current.Add(item); return Ok(item); } return BadRequest("Object is null"); } In my WebApiConfig.cs I have added following

Swagger use a custom swagger.json file aspnet core

风流意气都作罢 提交于 2020-02-24 11:48:39
问题 Pretty sure I am missing something clearly obvious but not seeing it. How can I use my updated swagger.json file? I took my boilerplate swagger/v1/swagger.json code and pasted it into the editor.swagger.io system. I then updated the descriptions etc, added examples to my models and then saved the contents as swagger.json. Moved the file into the root of my api application, set the file to copy always. public void ConfigureServices(IServiceCollection services) {... services.AddSwaggerGen(c =>