asp.net-web-api2

Is it possible to restrict access to REST API built using Web API 2?

旧巷老猫 提交于 2020-01-24 14:28:04
问题 I built a REST API using ASP.NET Web API 2, so I could deliver data from a backend database to my applications running on any platform (mobile, web, desktop etc) However up until now, I simply call the website with the controller I need data from and that's it, it sends back the JSON string in the response. But, the data is kind of special, and there is nothing to prevent another developer from simply calling the controllers and getting back the exact same data and building their own

need route for my web api 2 controller

落爺英雄遲暮 提交于 2020-01-24 08:48:28
问题 I have a simple WebApi2 controller that returns XML but I cannot add another method properly with the routing I have defined: namespace CBMI.WebAPIservice.Controllers { public class MarkersController : ApiController { public HttpResponseMessage Get(int? id) { int i = id.HasValue ? id.Value : 0; XmlDocument docContent = GetXmlDataFromDB(i); return new HttpResponseMessage { Content = new StringContent(docContent.InnerXml.ToString(), Encoding.UTF8, "application/xml") }; } public

Call web api with basic authentication always get 401 unauthorized from IIS

喜夏-厌秋 提交于 2020-01-24 05:44:12
问题 Tonight i come search some help about how to call a web api hosted in IIS. Everything work well in local from visual studio to iis express. But strangely, after publish on my IIS server. I always get 401 unauthorized :'( Here is the code i use and the settings from my IIS server. I will be very grateful if somebody can help me. Thank you ** The controller and the function i try to call (with basic authentication attribute) ** [HttpGet] [ActionName("Get_UserID")] [IdentityBasicAuthentication]

binding a date in angularjs using webapi and the bootstrap date picker

半城伤御伤魂 提交于 2020-01-24 03:53:26
问题 Given a WebApi2 service that returns json values like this: { id: 1109, effectiveDate: "2014-10-05T00:00:00", // the date is a string (newtonsoft.json) text: "Duis et rhoncus nibh. Cras rhoncus cursus diam", fundSource: "Test" } I need the date to appear in the bound angular / bootstrap / date picker correctly. I need to transform the date into the format yyyy-mm-dd (without the time) when binding it to an input box. Just a pointer to some documentation explaining what the correct way to

Treat empty query string parameters as empty strings, without using a class for parameters

白昼怎懂夜的黑 提交于 2020-01-22 20:00:33
问题 I am trying to pass multiple parameters to a httpget web api function. The key problem I am having is that empty query string parameters are being converted to null. I can solve this by creating a class like something below: public class CuttingParams { [DisplayFormat(ConvertEmptyStringToNull = false)] public string batch_number { get; set; } [DisplayFormat(ConvertEmptyStringToNull = false)] public string filter { get; set; } [DisplayFormat(ConvertEmptyStringToNull = false)] public string

Validate OAuth bearer token with form post

≡放荡痞女 提交于 2020-01-22 16:28:31
问题 I've created a OData based web back-end using Web API 2. This works really well, using AuthorizeAttribute on controllers. I'd like to be able to upload a files, via a standard html form and a submit. We are passing the OAuth token, which would normally be passed in the header of an OData request, as a hidden input field. Question: How do you validate this in the controller? 回答1: Then you need to un-protect the token, then from the "ticket" you check if there is principal and if it is

Validate OAuth bearer token with form post

旧街凉风 提交于 2020-01-22 16:28:17
问题 I've created a OData based web back-end using Web API 2. This works really well, using AuthorizeAttribute on controllers. I'd like to be able to upload a files, via a standard html form and a submit. We are passing the OAuth token, which would normally be passed in the header of an OData request, as a hidden input field. Question: How do you validate this in the controller? 回答1: Then you need to un-protect the token, then from the "ticket" you check if there is principal and if it is

Multiple parameters in a web api 2 get

混江龙づ霸主 提交于 2020-01-22 05:19:29
问题 I want to make a web api that is passed 4 parameters. Here is my route: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{email}/{firstname}/{lastname}/{source}" ); Here is the method signature public string GetId(string email, string firstname, string lastname, string source) Here is the calling url http://fakedomain.com/api/Contacts/GetId?email=user@domain.com&firstname=joe&lastname=shmoe&source=123 I get a 404 error. If I set each parameter to optional in

Web api passing array of integers to action method

ε祈祈猫儿з 提交于 2020-01-21 10:00:12
问题 I have this web api method: [HttpGet] [Route("WorkPlanList/{clientsId}/{date:datetime}")] public async Task<IHttpActionResult> WorkPlanList([FromUri]List<int> clientsId, [FromUri]DateTime date) { } Here is URI that I use to call the action method above: http://localhost/blabla/api/workPlan/WorkPlanList/5,4/2016-06-01 I set the break point on curved bracket and see date time value is passed perfect while clientsId value is 0 . Any idea why I get 0 on clientsId ? 回答1: Your problem intrigued me

Web api passing array of integers to action method

こ雲淡風輕ζ 提交于 2020-01-21 09:59:06
问题 I have this web api method: [HttpGet] [Route("WorkPlanList/{clientsId}/{date:datetime}")] public async Task<IHttpActionResult> WorkPlanList([FromUri]List<int> clientsId, [FromUri]DateTime date) { } Here is URI that I use to call the action method above: http://localhost/blabla/api/workPlan/WorkPlanList/5,4/2016-06-01 I set the break point on curved bracket and see date time value is passed perfect while clientsId value is 0 . Any idea why I get 0 on clientsId ? 回答1: Your problem intrigued me