asp.net-web-api

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

Why doesn't my oData response have navigation properties

只谈情不闲聊 提交于 2020-01-22 15:41:25
问题 If you look at the following sample oData feed you'll see included navigation properties for 'child' items to tell you which URL to follow: http://services.odata.org/OData/OData.svc/Suppliers?$format=json For example supplier 0 has a navigation property to products. This links to a list of products for that supplier. http://services.odata.org/OData/OData.svc/Suppliers(0)/Products?$format=json I'm trying to do the same with ODataConventionModelBuilder and EntitySetController<Product> so that

Handling CORS Preflight in Asp.net Web API

假如想象 提交于 2020-01-22 15:29:07
问题 I have three applications in my architecture. They are on the same server but having different port numbers. A - Token Application (port 4444) - Asp.net WebApi B - API Application (port 3333) - Asp.net WebApi C - UI Application (port 2222) - AngularJS App. The application flow is like below 1- The UI project gets the token from Token Application (It requires Windows Auth.) Ex : awxrsdsaWeffs12da 2- UI application puts this token to a custom header which is named as "accessToken" Ex :

“Can't bind multiple parameter to the request's content.” in web api and angularJs

社会主义新天地 提交于 2020-01-22 15:06:03
问题 When Multiple parameters pass in WebApi it results as an exception "Can't bind multiple parameter to the request's content." .Have any solution for following code public class A1 { public int id {get;set;} public string name {get;set;} } public class A2 { public int id2 {get;set;} public string name2 {get;set;} } [Route("Save")] [HttpPost] public string Save([FromBody]A1 Emp, [FromBody]List<A2> EmpMarks) { } JS file $http({ method: "post", url: "/api/Employee/Save", data: JSON.stringify({ Emp

“Can't bind multiple parameter to the request's content.” in web api and angularJs

孤街浪徒 提交于 2020-01-22 15:05:47
问题 When Multiple parameters pass in WebApi it results as an exception "Can't bind multiple parameter to the request's content." .Have any solution for following code public class A1 { public int id {get;set;} public string name {get;set;} } public class A2 { public int id2 {get;set;} public string name2 {get;set;} } [Route("Save")] [HttpPost] public string Save([FromBody]A1 Emp, [FromBody]List<A2> EmpMarks) { } JS file $http({ method: "post", url: "/api/Employee/Save", data: JSON.stringify({ Emp

Asp.net Web Api query string parameter with dash

百般思念 提交于 2020-01-22 14:52:08
问题 I have an Web.Api search method which receives the following parameter: [DataContract(Namespace = "", Name = "search")] public class SearchParameters { [DataMember(Name = "property-name")] public string PropertyName { get; set; } } In the Controller , i have this action: [HttpGet] public void Search([FromUri]SearchParameters request) { var parameters = 1; } I am trying to create a friendly name for PropertyName property ( property-name ), but the model binder doesn't recognizes the parameter:

Audio streaming by websockets

心不动则不痛 提交于 2020-01-22 13:16:05
问题 I'm going to create voice chat. My backend server works on Node.js and almost every connection between client and server uses socket.io. Is websockets appropriate for my use case? I prefer communication client -> server -> clients than P2P because I expect even 1000 clients connected to one room. If websocket is ok, then which method is the best to send AudioBuffer to server and playback on other clients? I do it like that: navigator.getUserMedia({audio: true}, initializeRecorder,

How to set up Elmah with ASP.NET Web API

醉酒当歌 提交于 2020-01-22 04:51:13
问题 I've tried many elmah nugets but they didn't work with ASP.NET Web API. Does anybody knows why? Is there any work around for that? 回答1: There are two options by using ELMAH to capture exceptions in WEB API. If you want to capture errors that are encountered in Actions and Controllers , i.e. in your business logic you can create a ActionFilterAttribute and log those exceptions to ELMAH. example: public class UnhandledExceptionFilter : ExceptionFilterAttribute { public override void OnException

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