asp.net-web-api2

Web API 2 RequireHttps allowing http connection

别等时光非礼了梦想. 提交于 2020-01-15 03:05:55
问题 I have created the following action in my MVC Web API 2 controller: [ResponseType(typeof(int))] [RequireHttps] public IHttpActionResult SaveLead(EcommerceLead lead) { } But in my test app I am making a call to http://localhost/api/savelead And it is working. Is there any way to make the action to only work if it is called over https, ie return a 404 if it isn't or something? 回答1: If you are using RequireHttps from Mvc namespace, it will not work with Web API. You can write a simple filter for

Windows Service hosting Web API 2 via Owin Starts and Immediately Stops with no Exceptions Thrown

两盒软妹~` 提交于 2020-01-14 14:08:52
问题 The title sums up my issue. I have try-catch blocks around the service's OnStart method and the Main method in the service, and no exception is ever thrown. The service starts and immediately stops, with the following message: The Foo service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs. The same behavior can be observed on the test server, so it is not machine-dependent. I've verified that the configuration

How to read/parse Content from OkNegotiatedContentResult?

我的未来我决定 提交于 2020-01-14 07:17:04
问题 In one of my API actions ( PostOrder ) I may be consuming another action in the API ( CancelOrder ). Both return a JSON formatted ResultOrderDTO type, set as a ResponseTypeAttribute for both actions, which looks like this: public class ResultOrderDTO { public int Id { get; set; } public OrderStatus StatusCode { get; set; } public string Status { get; set; } public string Description { get; set; } public string PaymentCode { get; set; } public List<string> Issues { get; set; } } What I need is

How to read/parse Content from OkNegotiatedContentResult?

两盒软妹~` 提交于 2020-01-14 07:16:11
问题 In one of my API actions ( PostOrder ) I may be consuming another action in the API ( CancelOrder ). Both return a JSON formatted ResultOrderDTO type, set as a ResponseTypeAttribute for both actions, which looks like this: public class ResultOrderDTO { public int Id { get; set; } public OrderStatus StatusCode { get; set; } public string Status { get; set; } public string Description { get; set; } public string PaymentCode { get; set; } public List<string> Issues { get; set; } } What I need is

How to create and update a relation between documents in DocumentDB using ASP.NET Web API

穿精又带淫゛_ 提交于 2020-01-14 05:22:13
问题 I am new to .NET and Azure, and am trying to create a simple Web API, to help me learn. I have two collections of DocumentDB documents. The documents in each collection are defined as follows: public class Log { [JsonProperty(PropertyName = "id")] public string Id { get; set; } [JsonProperty(PropertyName = "studentName")] public string StudentName { get; set; } [JsonProperty(PropertyName = "assignment")] public string Assignment { get; set; } [JsonProperty(PropertyName = "dueDate")] public

Web API Routing - Overloaded GET method causes 405 Method Not Allowed for other verbs

一世执手 提交于 2020-01-14 03:59:07
问题 I have an API controller that supports DELETE, GET, POST and PUT operations for an user object. The GET-one operation can retrieve a user account by their ID. But I also want to get the user by their UserName. I created separate methods for each and it seems to work fine as I can get the expected data both ways. // GET: api/UserAccounts/5 [HttpGet] [ResponseType(typeof(UserAccount))] [Route("~/api/UserAccounts/{id:int}")] public async Task<IHttpActionResult> GetUserAccount(int id) { ... } //

Azure API Management - Scope Claim NULL

↘锁芯ラ 提交于 2020-01-14 03:13:03
问题 I have a question regarding the SCP claim after using Azure to register an API that I've developed. I've followed various tutorials and sample applications. Everything validates correctly and I'm able to call a API Method from a trusted subsystem using primarily this tutorial: https://github.com/AzureADSamples/WebApp-WebAPI-OAuth2-AppIdentity-DotNet The problem that I'm having is when I try to validate the SCP claim: Claim scopeClaim = ClaimsPrincipal.Current.FindFirst("http://schemas

Azure API Management - Scope Claim NULL

五迷三道 提交于 2020-01-14 03:12:33
问题 I have a question regarding the SCP claim after using Azure to register an API that I've developed. I've followed various tutorials and sample applications. Everything validates correctly and I'm able to call a API Method from a trusted subsystem using primarily this tutorial: https://github.com/AzureADSamples/WebApp-WebAPI-OAuth2-AppIdentity-DotNet The problem that I'm having is when I try to validate the SCP claim: Claim scopeClaim = ClaimsPrincipal.Current.FindFirst("http://schemas

swagger UI is not showing anything in webapi

十年热恋 提交于 2020-01-13 10:04:38
问题 I followed this up to the xml doc part in order to create Swagger documentation using Swashbuckle. It should allow me to view the endpoints via (in my case): http://localhost:51854/swagger/ui/index Unfortunately, I cannot see any endpoints: Any ideas why and how to fix this? Please note that I created my webapi from an empty webapi project - maybe that's the problem. Something must be missing but I am not sure what ... I have now identified the following code as the root cause. In Global.asax

structuremap Web Api 2 Account Controller and individual accounts

无人久伴 提交于 2020-01-13 08:59:49
问题 I pretty New at IOC and web-api 2, but have got StructureMap to work on my own Controllers in web-api 2. What I don't have managed is to use StructureMap on the AccountController using Individual Accounts. I use AccountController out of the Box, and what I have managed so far is following: In Ioc.cs I have added following (Because of errors) x.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>(); x.For<DbContext>().Use(() => new ApplicationDbContext()); x.For<ISecureDataFormat