asp.net-web-api2

Angular 2 - Consuming restful api calls with windows authentication

天大地大妈咪最大 提交于 2019-12-06 04:30:32
I have a .net web api hosted on IIS 7 on a remote server which uses windows authentication. I want to access the web api using Angular 2 using TypeScript with node . Earlier i was getting an error 'Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource' I added this on the hosted Application's web.config <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> But now i get Unauthorised 401 error. I have read about adding the following code to allow cross domain

How to Deploy Owin Self Hosted Application In Production?

夙愿已清 提交于 2019-12-06 04:28:32
问题 I have an Asp.Net Owin Self Hosted WebApi application. The application can be installed as a windows service in production environment. Currently I'm running and accessing the service via url http://localhost:8000 successfully. Now I want to map the service to a domain to access it from public network. I have a registered domain and have control over it. Ex: www.myservice.com How can I point the domain to WebApi service for a Self Hosted Application? 回答1: In order to allow public access to

PushStreamContent stream does not flush under load

只愿长相守 提交于 2019-12-06 04:14:57
I am using PushStreamContent to keep a persistent connection to each client. Pushing short heartbeat messages to each client stream every 20 seconds works great with 100 clients, but at about 200 clients, the client first starts receiving it a few seconds delayed, then it doesn't show up at all. My controller code is // Based loosely on https://aspnetwebstack.codeplex.com/discussions/359056 // and http://blogs.msdn.com/b/henrikn/archive/2012/04/23/using-cookies-with-asp-net-web-api.aspx public class LiveController : ApiController { public HttpResponseMessage Get(HttpRequestMessage request) {

Dispose method in web api 2 web service

早过忘川 提交于 2019-12-06 04:02:56
问题 I am coding an MVC 5 internet application with a web api 2 web service. Do I need a dispose method for the DbContext class in a web service? It is not there as default. 回答1: Actually, System.Web.Http.ApiController already implements IDisposable : // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. // ... public abstract class ApiController : IHttpController, IDisposable { // ... #region IDisposable public void

OAuth Client Credential Flow - Refresh Tokens

折月煮酒 提交于 2019-12-06 03:44:48
The Scenario I've recently built an ASP.NET WEB API , and have protected its resources using OAuth Bearer Access Tokens. I've used the Client_Credentials Flow, as it will be accessed by clients as opposed to users. Here's the thing, when a client has successfully provided the client_id and the client_secret they receive a response like the following :- { "access_token": "<Access Token>", "token_type": "bearer", "expires_in": 1199, "refresh_token": "<Refresh Token>" } Refresh Tokens. Not knowing much about refresh tokens, i immediately assumed that a client would be able to provide the OAuth

404 Error when calling for the metadata using WEB API OData v4

怎甘沉沦 提交于 2019-12-06 03:38:15
I have tested the the call to the $metadata using postman and have found that when the MaxDataServiceVersion header is supplied the service always returns a 404 error. I have other posts about this using Breeze, but the best answer I can find simply says to comment out the line that adds this header. We are using SAPUI5 ODataModel in our client application and commenting out that header is not an option. Web API Config: ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<TBLMATERIAL>("TBLMATERIALs").EntityType.HasKey(o => o.MaterialNumber); config

ASP.NET WebAPI 2 deserializing JSON sets some nested objects to null

北战南征 提交于 2019-12-06 02:52:34
I am encountering an issue while sending some JSON from an AngularJS application to a ASP.Net WebAPI 2 back-end. What happens is that some properties from the incoming request are set to null during deserialization. Part of the request where the deserialization bug occurs: 12: {row: 9, column: 1, order: 13,…} column: 1 domainEntityProperty: {$id: "157", id: 2616,…} order: 13 renderType: {$id: "39", id: 1, class: "input"} row: 9 Above snippet is piece of the request that is being sent. It's a so called screen property being saved. The request has an array of these objects. The strange thing is

How to extend IdentityServer4 workflow to run custom code

隐身守侯 提交于 2019-12-06 02:35:30
I have a basic Identityserver4 implementation based on the quick start sample . In my startup I have the following: public void ConfigureServices(IServiceCollection services) { // configure identity server with in-memory stores, keys, clients and scopes services.AddIdentityServer() .AddTemporarySigningCredential() .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()); } public void Configure(IApplicationBuilder app) { ... app.UseIdentityServer(); } I want to extend the IdentityServer4 workflow so that after the access token is generated I can run business

Custom Json.NET JsonConverter is not being called while deserializing Web.API parameter

北慕城南 提交于 2019-12-06 02:28:47
I have a Web.API endpoint that takes an object like this as a parameter: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } public UserName UserName { get; set; } } For example: [Route("api/person")] [AcceptVerbs("POST")] public void UpdatePerson(Person person) { // etc. } I've defined a custom JsonConverter to convert from a JSON string property to my custom UserName class: public class UserNameJsonDeserializer : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(UserName); }

Refresh tokens in oauth2 should not be replaced when getting a new access token

自作多情 提交于 2019-12-06 01:34:05
问题 Is the statement in the title correct? I'm basing the question on the work done by Taiseer Joudeh (thanks for your work on this subject, btw) at http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/. If I understand the behavior of refresh tokens correctly, when an access token expires, we should call the token endpoint of our auth server with something like 'grant_type=refresh_token&refresh_token=' + token and we will get back a new access