asp.net-web-api

How to set the Origin Request Header

坚强是说给别人听的谎言 提交于 2020-04-10 10:23:33
问题 I want to send an AJAX request to a remote API. function Gettest(CourseID) { var param = { "CourseID": CourseID}; param = JSON.stringify(param); $.ajax({ type: "Post", url: apiurl + "Course/DelCoursetargetedaudience", contentType: "application/json; charset=utf-8", data: param, dataType: "json", success: function (data) { }, error: function (response) { } }); }; But I need to change the origin name, before sending the request. Please refer to the image below. 回答1: In short: you cannot. As

How to set the Origin Request Header

邮差的信 提交于 2020-04-10 10:21:53
问题 I want to send an AJAX request to a remote API. function Gettest(CourseID) { var param = { "CourseID": CourseID}; param = JSON.stringify(param); $.ajax({ type: "Post", url: apiurl + "Course/DelCoursetargetedaudience", contentType: "application/json; charset=utf-8", data: param, dataType: "json", success: function (data) { }, error: function (response) { } }); }; But I need to change the origin name, before sending the request. Please refer to the image below. 回答1: In short: you cannot. As

Azure Web App Temp file cleaning responsibility

烈酒焚心 提交于 2020-04-10 07:37:11
问题 In one of my Azure Web App Web API application, I am creating temp files using this code in a Get method string path = Path.GetTempFileName(); // do some writing on this file. then read var fileStream = File.OpenRead(path); // then returning this stream as a HttpResponseMessage response My question is, in a managed environment like this (not in VM), do I need to clear those temporary files by myself? Shouldn't Azure itself supposed to clear those temp files? 回答1: Those files only get cleaned

How to add ASP.Net identity to Asp.Net Core when webApi template is selected?

喜夏-厌秋 提交于 2020-04-07 17:43:18
问题 I have created a .NET Core project with WebApi template selected includes no authentication. I want to add ASP.NET identity in it for role based authorization. How can I achieve this? 回答1: This will give you a bear bones webapi with aspnet core identity, first create your project (this assumes you've created a new folder and you're in it): dotnet new webapi Add aspnet core identity: dotnet add package Microsoft.AspNetCore.Identity Add some database provider to store your data: dotnet add

Azure app oauth2 generating wrong access token in Client Credentials grant type

早过忘川 提交于 2020-04-07 08:25:46
问题 I am a beginner in using Azure AD with OAuth2. I deployed a sample WEB API in my Azure AD. I consume my WEB API through the Postman application. Before consume the WEB API in Postman I need to generate the access token. But when i generate the access token in post man it's always accept the Grant Type - Authentication Code . When i change the value to Client Credentials the generated access token is not accepted in the API. it's shows UnAuthorized message. In Azure portal - app settings

How to get the Windows user's login time?

断了今生、忘了曾经 提交于 2020-04-05 05:25:13
问题 Is there a way in C# to get the time when the current user logged in? A command called quser in command prompt will list some basic information about current users, including LOGON TIME. Is there a System property or something I can access in c# which I can get the user's login time from? I am getting username by Environment.UserName property. Need the login time. I've tried this: using System.DirectoryServices; using System.DirectoryServices.AccountManagement; Console.WriteLine("Login Time:

Basic Authentication with a Guid token for REST api instead of username/password

旧城冷巷雨未停 提交于 2020-04-01 03:55:37
问题 Overview I am developing a mobile application using PhoneGap with REST API for the backend. The REST API won't be utilised by third-party developers, but will be application-specific, so there is no need for oAuth to be implemented. Hence, I am planning to use Basic Authentication where in the User enters their Username/password to access the API resources. All API communication will be on SSL. Basic Authentication with Token Instead of letting the application store the username/password and

Basic Authentication with a Guid token for REST api instead of username/password

我是研究僧i 提交于 2020-04-01 03:54:50
问题 Overview I am developing a mobile application using PhoneGap with REST API for the backend. The REST API won't be utilised by third-party developers, but will be application-specific, so there is no need for oAuth to be implemented. Hence, I am planning to use Basic Authentication where in the User enters their Username/password to access the API resources. All API communication will be on SSL. Basic Authentication with Token Instead of letting the application store the username/password and

Basic Authentication with a Guid token for REST api instead of username/password

折月煮酒 提交于 2020-04-01 03:53:32
问题 Overview I am developing a mobile application using PhoneGap with REST API for the backend. The REST API won't be utilised by third-party developers, but will be application-specific, so there is no need for oAuth to be implemented. Hence, I am planning to use Basic Authentication where in the User enters their Username/password to access the API resources. All API communication will be on SSL. Basic Authentication with Token Instead of letting the application store the username/password and

Get response in JSON from API

霸气de小男生 提交于 2020-03-26 04:43:12
问题 I am using HttpClient to consume an external API from an ASP.NET Web API controller. I am not using authentication, just a token, so I have: using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await httpClient.GetAsync(endpoint); } I am getting the response always in XML format but I am sending header with "application