asp.net-web-api2

Azure AD + ADAL.js + App Service - Only one claim on ClaimsPrincipal.Current.Claims

别来无恙 提交于 2020-01-17 07:52:43
问题 I'm facing a very strange issue related to Azure AD and Azure App Service (Web App). I have a SPA built with Angular 1.5 + ADAL.JS, WebAPI (hosted on App Service) and Azure AD. I've created two applications into my Azure AD directory: - one native (SPA) - one web application (WebAPI). The Login and Logout workflows are working fine locally and on Azure. However, when I'm running on Azure and checking if an user is member of a group, the ClaimsPrincipal.Current.Claims only have one Claim. (I

How to handle Http Status code when making use of ReadAsStringAsync()

删除回忆录丶 提交于 2020-01-17 01:45:12
问题 I have a JavaScript client which makes Ajax call to a .net service (Lets call it First service). First service then makes call to another .net Controller (Call it Second Service). In this controller, I am throwing some exception. On the first line I am saying: //Code from Second Service [HttpPost] public HttpResponseMessage Results(ParamsModel data) { throw new Exception("Exception for testing purpose"); } //Code from First Service [HttpPost] public ActionResult Results(ParamsModel data) {

ASP.NET Web API 2 - POST / jQuery

时光毁灭记忆、已成空白 提交于 2020-01-16 05:51:12
问题 I am trying to post an object to the server where I am using Web API 2. The code as follows: $.ajax({ cache: false, type: "POST", url: "/api/Employees", data: { EmployeeId: 1 }, success: function(result) { console.log("employees saved successfully"); }, error: function(result) { } }); As for the Web API: public class EmployeesController : ApiController { // POST api/<controller> public void Post([FromBody]Employee value) { } } public class Employee { public Int32 EmployeeId { get; set; }

Does returning IHttpActionResult stop request execution

拜拜、爱过 提交于 2020-01-16 05:47:47
问题 Here @GlennBlock mentioned that throwing HttpResponseException immediately stops request execution while returning HttpResponseMessage does not stop request propagation (as I understood it). The exception is useful to immediately stop processing and exit. If instead I return HttpResponseMessage, the request will happily continue the rest of it's processing and return a 404. The main difference being end the request or not. In .NET Web API 2 you can also return IHttpActionResult from

Web API 2.2, Inherited Controller with Route Overrides (Is this possible)?

瘦欲@ 提交于 2020-01-16 05:17:30
问题 So I have a generic base controller implementing CRUD, which derives from APIController . public class GenericController<TEntity> : ApiController where TEntity : class { private readonly GenericModel<TEntity> _model; public IModel Model { get { return _model; } } public GenericController(IGenericModel<TEntity> model) { _model = (GenericModel<TEntity>)model; } [HttpPost, Route] public IHttpActionResult Post(TEntity entity) { TEntity newEntity = _model.Create(entity); String urlLink = $"

C# - Cannot call a HttpConfiguration Extension Methods

大憨熊 提交于 2020-01-16 04:49:06
问题 I cannot call an HttpConfiguration extension method: using System.Configuration; using System.Web.Http; ... var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); // <-- error Error: 'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapHttpAttributeRoutes' and no extension method 'MapHttpAttributeRoutes' accepting a first argument of type 'System.Web.Http.HttpConfiguration' could be found (are you missing a using directive or an assembly reference?) I

How to send a custom object from OnException method?

寵の児 提交于 2020-01-15 15:31:32
问题 public override void OnException( System.Web.Http.Filters.HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext.Exception != null) Elmah.ErrorSignal.FromCurrentContext().Raise(actionExecutedContext.Exception); base.OnException(actionExecutedContext); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(actionExecutedContext.Exception.Message), ReasonPhrase = "Deadly Exception", }); } This is my filter

How to send a custom object from OnException method?

回眸只為那壹抹淺笑 提交于 2020-01-15 15:30:00
问题 public override void OnException( System.Web.Http.Filters.HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext.Exception != null) Elmah.ErrorSignal.FromCurrentContext().Raise(actionExecutedContext.Exception); base.OnException(actionExecutedContext); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(actionExecutedContext.Exception.Message), ReasonPhrase = "Deadly Exception", }); } This is my filter

WebApi 2 Oauth2 Android client

点点圈 提交于 2020-01-15 07:24:48
问题 I want my android app to communicate with an Asp.net WebApi2 secured by Oauth2. All samples I've found only show how it is done for websites. I'm able to get an access token from the "/token" endpoint and I add this token to the http header in the Autorization attribute. However, I always get: "Authorization has been denied for this request." My Startup Auth looks like: public partial class Startup { public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; } public

asp.net webapi dynamic authorization

我的梦境 提交于 2020-01-15 07:23:27
问题 I am new to webapi and mvc and I am struggling to find a best practice for handling authorizations dynamically based on roles and ownership of the resource. For example an account page that should allow employee admins, employee call center or the owning client to Get, Post, Put or Delete account information. So an admin and call center employee should be able to Get, Post, Put or Delete any request for any userid, but a client should only be able to perform these actions on resources owned