asp.net-web-api

Web API Basic Auth inside an MVC app with Identity Auth

浪子不回头ぞ 提交于 2020-01-14 14:12:11
问题 So I have a C# MVC app using Identity for its authentication. I now have a need to expose a few things via Web API to some of my clients. Instead of building a separate app, project, deployment... I've simply added an API Controller to my existing project. To keep things simple for my clients, I've decided to use Basic Auth , opting rather to force my clients into using SSL connections to my API. I've followed this very useful tutorial to implement the Basic Auth in my API: http://www

Web API Basic Auth inside an MVC app with Identity Auth

落爺英雄遲暮 提交于 2020-01-14 14:11:49
问题 So I have a C# MVC app using Identity for its authentication. I now have a need to expose a few things via Web API to some of my clients. Instead of building a separate app, project, deployment... I've simply added an API Controller to my existing project. To keep things simple for my clients, I've decided to use Basic Auth , opting rather to force my clients into using SSL connections to my API. I've followed this very useful tutorial to implement the Basic Auth in my API: http://www

Setting Cookie values in HttpAuthenticationContext for IAuthenticationFilter

↘锁芯ラ 提交于 2020-01-14 14:06:12
问题 I have a need to read/write cookies during the authentication step of a WebAPI pipeline. I have created a custom filter for this. In an attempt to comply with self-hosting concepts, what would be a safe way to access and write cookies out to the client? Rick Strahl commented that if we use HttpContext.Current.Response.Cookies.Add() , and my application is self-hosted, the context may/will not exist. So how would I write a cookie out to the client using HttpAuthenticationContext and still be

Setting Cookie values in HttpAuthenticationContext for IAuthenticationFilter

♀尐吖头ヾ 提交于 2020-01-14 14:05:31
问题 I have a need to read/write cookies during the authentication step of a WebAPI pipeline. I have created a custom filter for this. In an attempt to comply with self-hosting concepts, what would be a safe way to access and write cookies out to the client? Rick Strahl commented that if we use HttpContext.Current.Response.Cookies.Add() , and my application is self-hosted, the context may/will not exist. So how would I write a cookie out to the client using HttpAuthenticationContext and still be

Setting Cookie values in HttpAuthenticationContext for IAuthenticationFilter

邮差的信 提交于 2020-01-14 14:05:31
问题 I have a need to read/write cookies during the authentication step of a WebAPI pipeline. I have created a custom filter for this. In an attempt to comply with self-hosting concepts, what would be a safe way to access and write cookies out to the client? Rick Strahl commented that if we use HttpContext.Current.Response.Cookies.Add() , and my application is self-hosted, the context may/will not exist. So how would I write a cookie out to the client using HttpAuthenticationContext and still be

Using ExceptionFilterAttribute in Web API

家住魔仙堡 提交于 2020-01-14 12:53:33
问题 I am trying to implement the error handling in the created Web API, need to return the exception details in JSON format. I created the BALExceptionFilterAttribute like public class BALExceptionFilterAttribute : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext actionExecutedContext) { base.OnException(actionExecutedContext); actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(HttpStatusCode.BadRequest, new { error =

How to use async and await in LINQ?

天大地大妈咪最大 提交于 2020-01-14 10:29:08
问题 I'm new to ASP.NET and was trying to work on a sample project. I know this is a silly qs but please bear with me. My code below is returning only one result even when there are multiple rows returned in the SQL query. I realize that FirstOrDefaultAsync returns only the first element. I was going through the documentation here: https://msdn.microsoft.com/en-us/library/system.data.entity.queryableextensions(v=vs.113).aspx but I couldn't find what to use instead of FirstOrDefaultAsync that would

Ninject throws Activation Exception in a WebApi project with multiple assemblies

大城市里の小女人 提交于 2020-01-14 10:23:08
问题 My asp.net WebApi project comprises of multiple assemblies for Services, Core and Data Access. In an attempt to use Ninject as my DI container in the project, I added Ninject.Web.Common package from NuGet. Then, I Implemented IDependencyResolver as: public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver { readonly IKernel kernel; public NinjectDependencyResolver(IKernel kernel) : base(kernel) { this.kernel = kernel; } public IDependencyScope BeginScope() { return

Ninject throws Activation Exception in a WebApi project with multiple assemblies

百般思念 提交于 2020-01-14 10:23:07
问题 My asp.net WebApi project comprises of multiple assemblies for Services, Core and Data Access. In an attempt to use Ninject as my DI container in the project, I added Ninject.Web.Common package from NuGet. Then, I Implemented IDependencyResolver as: public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver { readonly IKernel kernel; public NinjectDependencyResolver(IKernel kernel) : base(kernel) { this.kernel = kernel; } public IDependencyScope BeginScope() { return

Ninject throws Activation Exception in a WebApi project with multiple assemblies

可紊 提交于 2020-01-14 10:23:05
问题 My asp.net WebApi project comprises of multiple assemblies for Services, Core and Data Access. In an attempt to use Ninject as my DI container in the project, I added Ninject.Web.Common package from NuGet. Then, I Implemented IDependencyResolver as: public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver { readonly IKernel kernel; public NinjectDependencyResolver(IKernel kernel) : base(kernel) { this.kernel = kernel; } public IDependencyScope BeginScope() { return