asp.net-web-api

How to link exceptions to requests in Application Insights on Azure?

杀马特。学长 韩版系。学妹 提交于 2019-12-29 17:47:01
问题 We are using Owin on Azure for a REST service, and have to report to Application Insights directly. We want to log exceptions and requests. Right now we have this: using AppFunc = Func<IDictionary<string, object>, Task>; public class InsightsReportMiddleware { readonly AppFunc next; readonly TelemetryClient telemetryClient; public InsightsReportMiddleware(AppFunc next, TelemetryClient telemetryClient) { if (next == null) { throw new ArgumentNullException("next"); } this.telemetryClient =

How to link exceptions to requests in Application Insights on Azure?

左心房为你撑大大i 提交于 2019-12-29 17:46:05
问题 We are using Owin on Azure for a REST service, and have to report to Application Insights directly. We want to log exceptions and requests. Right now we have this: using AppFunc = Func<IDictionary<string, object>, Task>; public class InsightsReportMiddleware { readonly AppFunc next; readonly TelemetryClient telemetryClient; public InsightsReportMiddleware(AppFunc next, TelemetryClient telemetryClient) { if (next == null) { throw new ArgumentNullException("next"); } this.telemetryClient =

How to return Json object on Web API Controller

百般思念 提交于 2019-12-29 11:35:13
问题 I used this below code on my asp.net controller to return Json object on my Ajax on javascript public JsonResult myMethod() { // return a Json Object, you could define a new class return Json(new { Success = true, //error Message = "Success" //return exception }); } Jquery-Ajax: $.ajax({ type: "POST", url: url_ , data: search, success: function(data) { //Show Json Properties from Controller ( If Success == false show exception Message from controller ) if (data.Success) { alert(data.Message);

How can you unit test an Action Filter in ASP.NET Web Api?

血红的双手。 提交于 2019-12-29 10:13:55
问题 I was looking to add an Action Filter to my service to handle adding link data to the response message. I have found that I need to mock HttpActionExecutedContext but it's a difficult class to mock, how are you dealing with Action Filter testing? 回答1: You can create a fake for HttpActionExecutedContext as below: public static HttpActionContext CreateActionContext(HttpControllerContext controllerContext = null, HttpActionDescriptor actionDescriptor = null) { HttpControllerContext context =

Using JWT to implement Authentication on Asp.net web API

删除回忆录丶 提交于 2019-12-29 10:08:10
问题 I have been reading about JWT. But from what I read it is not an authentication mechanism but more like a crucial component in a Authentication mechanism. I have currently implemented a solution which works, but it was just to try out JWT and see how it works. But what I am after now is how one should make use of it. From my experience of it its basically just an encryption mechanism that gives you a unique encrypted key. You are also able to put information inside of this token. I am wanting

Parsing/Consuming a MultipartFormDataContent (set by MVC) on the WebApi side

倖福魔咒の 提交于 2019-12-29 09:23:14
问题 I got the ByteArrayContent to work /* MVC Method , ByteArrayContent */ private async Task<HttpResponseMessage> ExecuteProxy(string url) { using (var client = new HttpClient(HttpClientHandlerFactory.GetWindowsAuthenticationHttpClientHandler())) { byte[] byte1 = new byte[] { 1, 2, 3 }; ByteArrayContent byteContent = new ByteArrayContent(byte1); this.Request.Method = HttpMethod.Post; this.Request.Content = byteContent; return await client.SendAsync(this.Request); } } /* WebApi Delegating Handler

change facebook redirect_uri web api

家住魔仙堡 提交于 2019-12-29 08:54:16
问题 I was wondering if someone could give me a hand or point me in the right direction. I've setup facebook social sign in within my web api 2 project and it works correctly. However, when I deploy it to production I have found that the redirect_uri is showing HTTP instead of HTTPS and this causes the service to crash. What I wanted to know was firstly how the redirect_uri is constructed and whether there was any way of updating it. The whole reason this is happening is because of our load

httpclient call to webapi to post data not working

*爱你&永不变心* 提交于 2019-12-29 08:01:51
问题 I need to make a simple webapi call to post method with string argument. Below is the code I'm trying, but when the breakpoint is hit on the webapi method, the received value is null . StringContent stringContent = new System.Net.Http.StringContent("{ \"firstName\": \"John\" }", System.Text.Encoding.UTF8, "application/json"); HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PostAsync(url.ToString(), stringContent); and server side code: // POST api/values

httpclient call to webapi to post data not working

杀马特。学长 韩版系。学妹 提交于 2019-12-29 08:01:46
问题 I need to make a simple webapi call to post method with string argument. Below is the code I'm trying, but when the breakpoint is hit on the webapi method, the received value is null . StringContent stringContent = new System.Net.Http.StringContent("{ \"firstName\": \"John\" }", System.Text.Encoding.UTF8, "application/json"); HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PostAsync(url.ToString(), stringContent); and server side code: // POST api/values

Deserialization / model binding in MVC4 webapi does not work with arrays

半腔热情 提交于 2019-12-29 07:53:04
问题 I'm using the new WebApi which is part of MVC4 beta. I have the following class: public class Voucher { public string Id { get; set; } public string TableId { get; set; } public Product[] Products { get; set; } } My controller looks like this: public class VouchersController : ApiController { public Voucher PostVoucher(Voucher voucher) { //.... } } On the client side I serialize the data using an XmlSerializer . The output looks like expected and the Products array is serialized. If I post