FAQ Database Discussion Community


How does Katana/IIS handle conflicts. WebApi in WinService and website in IIS - who wins?l

iis,asp.net-web-api,owin,katana,topshelf
I have a IIS configured with a lot of websites. Now I want to install a WebApi hosted with OWIN/Katana in a Windows Service (using topshelf). Could my WebApi be using the same port as IIS? http://myserver/webapp1/ (This goes to IIS) http://myserver/api/method/ (This should go to OWIN inside my windows...

Why is owin middleware created a second time after the HttpRequest ended

c#,asp.net-mvc-5,owin,owin-middleware
After a question as per why the ApplicationDbContext from Asp.Net Identity is created and disposed twice per Request I did some research why this would happen. I found that the ApplicationDbContext is actualy created once per HttpRequest but when using the Owin pipeline the Owin Middleware will be created a...

MVC5 Login to custom Database

asp.net-mvc,authentication,login,asp.net-mvc-5,owin
What if you have your own database and a BAL (Business Access Layer) and don't want to use DefaultConnection and the template ASPNET database tables but my own user tables? How can you use a custom database? ConnectionString: public class AppDbContext : IdentityDbContext<AppUser> { public AppDbContext() : base("DefaultConnection") { }...

Ninject.ActivationException thrown only on first web request (WebAPI 2, OWN 3, Ninject 3)

asp.net-web-api,ninject,owin
I am attempting to create a "barebones" WebAPI project that uses OWIN middleware, Ninject DI, and ultimately to be hosted in IIS. I have followed instructions found in an article, "Befriending ASP.NET Web.API2, OWIN and Ninject," here: http://www.alexzaitzev.pro/2014/11/webapi2-owin-and-ninject.html, except I used an empty Web Application Project, and did not tick...

Can I use ASPNetIdentity and ActiveDirectory?

active-directory,owin,aspnet-identity
I have been looking over examples of using Asp.Net Identity and various providers to supply authentication using facebook, twitter, etc. I have an MVC 6 solution, currently being developed using VS2015 RC. It will be deployed to an organisational IIS. AD is primarily used to authenticate users, the majority of...

ASP.NET Identity Google Callbackpath throwing internal server error 500

asp.net-mvc,google-api,asp.net-identity,owin
I am trying to configure google authentication in my existing asp.net mvc 5 application using Identity 2.0. In Startup.Auth i have configured the google authentication options like so. app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions { ClientId = ".....", ClientSecret = ".....", CallbackPath = new PathString("/Account/ExternalLoginCallback") } In trying to test the callback manually in...

ASP .Net VNext and Owin

asp.net,.net,iis,owin,asp.net-5
I am exploring the features of ASP .NET VNext. In previous versions of .NET, Owin is used for self hosting of applications as well as hosting in any Owin compatible web servers including IIS. As per my understanding, ASP .NET VNext itself is host agnostic and has commands for self...

How to configure OData end point in a self-hosted Web API application

c#,odata,asp.net-web-api2,owin,self-host
I'm building an OWIN self-hosted Web API 2 service. I need for this service to expose OData end points. The traditional IIS-hosted method involves App_Start/WebApiConfig.cs: using ProductService.Models; using System.Web.OData.Builder; using System.Web.OData.Extensions; public static class WebApiConfig { public static void Register(HttpConfiguration config) { // New code: ODataModelBuilder builder = new ODataConventionModelBuilder();...

Owin Hosted NancyFX app returns Could not load type Nancy.Hosting.Aspnet.NancyHttpRequestHandler once published to IIS

owin,iis-8,nancy
While it works perfectly when run locally through VS Studio's included IIS Express, my application chokes once deployed to IIS 8: System.Web.HttpException: Could not load type 'Nancy.Hosting.Aspnet.NancyHttpRequestHandler'. Back-end is MS Owin, written in VB (.NET 4.5), which registers 3 middlewares: OAuth server, JWT bearer Authentication, and Nancy. Front end is...

Reinitialize service in ASP.NET Web API

c#,asp.net,asp.net-web-api,owin
I deployed my service within a self hosted (OWIN) ASP.NET Web API: config.Services.Replace(typeof(IHttpControllerTypeResolver), new MyHttpControllerTypeResolver()); Because of some changes in the underlying system I would like to reinitialize the service (singleton; instance of MyHttpControllerTypeResolver). Is this possible?...

How does Katana relate to ASP.NET 5 applications on IIS?

asp.net-mvc,asp.net-web-api,owin,katana
I understand what OWIN is, and it is good, and generally that Katana is a Microsoft implementation the standard in terms of the ASP.NET ecosystem. I've also read that Katana has only so far been designed to work with WebApi and SignalR, since these take no dependency System.Web. Cool. However,...

Can't get the OWIN Startup class to run in IIS Express after renaming ASP.NET project file

asp.net,asp.net-web-api,owin,iis-express
I've got a situation where I needed to change the solution and project names within a OWIN-based WebAPI website. Everything worked great before this change, and to my knowledge the renaming was successful because of the following: The solution builds fine and all my unit tests run sucessfully both locally...

“No owin.Environment item was found in the context.” when not in debug mode

c#,asp.net-mvc,owin,katana
I'm having a weird issue regarding Owin and its context. I have a controller action that looks like this [HttpPost] public ActionResult Login(string username, string password) { var ctx = HttpContext.GetOwinContext(); // code omitted return new HttpUnauthorizedResult(); } If I set a breakpoint at var ctx and debug my application...

ReturnForAnyArgs without using NSubstitute

mocking,asp.net-identity,owin,nsubstitute
I am unit testing a Post method that in its implementation uses a Microsoft.AspNet.Identity.Owin.SignInManager because SignInManager inherit from a class and not an interface I cannot use NSubstitute to mock the SignInManager object. Therefore I cannot use the ReturnForAnyArgs method to get it to return a SignInStatus of say Success....

Asynchronous OWIN pipeline

asp.net,asynchronous,owin
I'm using ASP.NET 5 (core) and the OWIN pipeline. I can see many examples of how to output a response, ie: http://odetocode.com/blogs/scott/archive/2013/11/11/writing-owin-middleware.aspx However, if you take the following: public class Startup { public void Configure(IApplicationBuilder app) { app.Run(context => { MvcHandler mvcHandler = new MvcHandler(); return mvcHandler.ProcessRequest(context); }); } }...

Cannot use multiple options OWIN

c#,web-api,owin
I've got a small problem regarding a server hosted with OWIN. I'm trying to make it accessible to the local network which means I have to add a few extra options: // Start OWIN host StartOptions options = new StartOptions(); options.Urls.Add("http://localhost:4004"); //options.Urls.Add("http://127.0.0.1:4004"); //options.Urls.Add(string.Format("http://{0}:4004", Environment.MachineName)); using (WebApp.Start<Startup>(options)) { // Create HttpCient...

using mono to host a asp.net owin webpage on the pi results in bad host

c#,asp.net,mono,raspberry-pi,owin
While i was trying to port a owin asp.net website to the pi, (raspberry pi model b) I ended up with a website displaying the error page : Bad Request (Invalid host) On the pi i am running raspbian wheezy. I installed mono (version 3.2.8). For a simple console aplication...

Using Autofac with Web Api 2 and Owin

c#,dependency-injection,autofac,asp.net-web-api2,owin
Im new to DI libraries and trying to use Autofac in a WebApi 2 project with Owin. This is my Owin Startup class, [assembly: OwinStartup(typeof(FMIS.SIGMA.WebApi.Startup))] namespace FMIS.SIGMA.WebApi { public class Startup { public void Configuration(IAppBuilder app) { var builder = new ContainerBuilder(); var config = new HttpConfiguration(); WebApiConfig.Register(config); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); var...

Using Simple Injector in Web API and OWIN

c#,asp.net-web-api2,owin,simple-injector
I'm experiencing the same problem as described here and my set up is almost identical to this that is actually based on this guide. When I access a method in my controller I get this An error occurred when trying to create a controller of type 'TestController'. Make sure that...

How to get HttpRequestBase from IOwinContext

c#,.net,asp.net-web-api,asp.net-web-api2,owin
I started using Owin self host for my API and now I'm trying to fix some tests, which started to fail, because Owin does not support HttpContext.Current Now I'm stuck in getting HttpRequestBase from IOwinContext. Here's my old code, which I used before Owin: public static HttpRequestBase GetRequestBase(this HttpRequestMessage request)...

Storing hash of username using ASP.NET identity

owin,asp.net-identity-2,asp.net-authorization
I'm writing an application which needs to have personally identifiable information removed/absent at all times from the database. Given that someone may use their real name in their username, and that an email address may be present in their AspUserIdentity records, I have decided one solution might be to hash...

ASP.NET Identity Email validation token is always invalid

c#,asp.net-mvc,asp.net-web-api,asp.net-identity,owin
I'm trying to implement a invitation system where newly created accounts received a confirmation token by email using UserManager.GenerateEmailConfirmationToken and UserManager.ConfirmEmail. However the ConfirmEmail method is always returning false. As per suggestion in this post I implemented my MachineKeyDataProtector and registered in Unity like this: container.RegisterType<IUserTokenProvider<User, Guid>, DataProtectorTokenProvider<User, Guid>>(new InjectionConstructor(new...

MVC - Mixed Auth - OWIN + Windows Auth

c#,asp.net-mvc,asp.net-mvc-5,owin,windows-authentication
I need to have both windows authentication and owin (forms) authentication but i can't get it to work. Probably the best option is to have two sites that have different authentication methods. I found a project that does what i want: MVC5-MixedAuth. But it uses IISExpress and i can't get...

OWIN not firing up if project not set as Startup with IIS Express

visual-studio-2013,owin,iis-express,katana
I have a solution in VS2013 with the following setup: App.Web (Web Project with only static files) App.Web.API (Web API project with OWIN) Both the projects have a default url pointing to their own localhost:portX (I am using IIS Express), so App.Web is listening on localhost:2222 and APP.Web.API is listening...

Katana+OWIN Context Get HTTP Referrer?

owin,katana
IOwinContext does not appear to have the HTTP Referrer in it, and I need to grab it. What is the right way to get that particular variable? IOwinContext has several Typed PEMs but I don't see referer in particular. The system I am working is self-hosted. Thanks....

A middleware should always invoke the next?

owin,asp.net-5
I've been trying to understand how ASP.NET 5 pipeline middlewares really work. A middleware, as I know, is just a Func<RequestDelegate, RequestDelegate>, which is a pointer to a method that receives a reference to the next request delegate and returns a new one that wraps the next. We can of...

Implement OWIN Authentication in Existing MVC 5 app

c#,asp.net-mvc-5,asp.net-identity,owin
I am currently struggling to understand how exactly the OWIN Authentication works within MVC 5. I have read numerous articles, but it all seems as if they expect you to know quite a bit about this. I want to implement Authentication in my MVC 5 app, but have not yet...

ASP.Net Identity Login Redirect Enforce Protocol (Https)

asp.net-mvc,owin,asp.net-identity-2
Hopefully I'm just missing something really simple/obvious - why, and more importantly, how do you maintain (or force) the protocol during the redirect to Login? To illustrate: the original protocol is https one would think this should be the "default" for something like login, but as shown, the redirect (seems)...

Google Auth does not work in template asp.net mvc project

asp.net-mvc,google-oauth,owin
So I have VS 2013 update 4 and I created ASP.NET MVC application from template and configured Google authentication by using UseGoogleAuthentication method and passing client ID and secret. But for some reason once I click 'Accept' button google page I'm redirected to the page I expect but there is...

Is it possible to set an ASP.NET Owin security cookie's ExpireTimeSpan on a per-user basis?

c#,asp.net,asp.net-mvc,cookies,owin
We have an ASP.NET MVC 5 app using Owin cookie authentication. Currently, we set up cookie authentication as follows: public partial class Startup { public void ConfigureAuth(IAppBuilder app) { var timeoutInMinutes = int.Parse(ConfigurationManager.AppSettings["cookie.timeout-minutes"]); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, AuthenticationMode = AuthenticationMode.Active, LoginPath = new PathString("/"), ExpireTimeSpan =...

How to define multiple partial Owin Startup classes and have them all run their code

asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-identity,owin
I'm working on an MVC application that will feature a "plugin" architecture. Basically there will be a main "host" project that will dynamically load other projects at runtime. We want to move all ASP.NET Identity related stuff into its own separate plugin project. The main host project already contains an...

ASP.Net MVC identity infinite redirect loop

asp.net,asp.net-mvc,owin,aspnet-identity
I have an ASP.Net MVC5 application, using the Identity "out of the box" template, as per ASP.Net Identity 2.0.0. I need to upgrade it to use the newer code that is in the latest ASP.Net MVC template, namely the use of the SignInManager class. I have done some A|B comparisons...

How to use IAppBuilder-based Owin Middleware in ASP.NET 5

c#,asp.net,owin
ASP.NET 5 (aspnet vnext) is OWIN based like Katana was, but has different abstractions. Notably IAppBuilder has been replaced by IApplicationBuilder. Many middleware libraries depend on IAppBuilder and have not been updated to support ASP.NET 5 How can I use this OWIN middleware in APS.NET 5 middleware. Both are OWIN...

Using both OAuth and Basic Auth in Asp.Net Web Api with Owin

asp.net-web-api,oauth,owin
I've implemented OAuth authentication in my Web Api project based on these blog posts It works well, including the refresh token logic. I want to add an option for basic authentication as well for a couple of calls for scheduled jobs. I've tried adding a Basic Auth solution as middleware...

SignalR and Websockets on Mono

c#,.net,mono,.net-4.5,owin
I've done hours of scouring, trying to figure out why the websockets transport doesn't work through signalr on my c# 4.5 application running on linux via mono 4.0.1. References in my project: Microsoft.Owin.Host.HttpListener Microsoft.Owin.Host.SystemWeb Right now, I'm trying to figure out where the bottleneck is that is preventing websockets from...

Owin auth - how to get IP address of client requesting the auth token

c#,.net,authentication,owin
Using Owin Security, I'm trying to make the API have 2 methods of authentications. Is there a property in the context variable (OAuthGrantResourceOwnerCredentialsContext) that lets me access the IP address of the client sending the initial request for an auth token to the API? A basic strip of my auth...

How to create a Certificate Signing Request (CSR) OWIN Selfhosted

owin,nancy,csr
Would I use the IIS Manager to create this CSR even though the web application is not hosted in IIS? I have a .Net app using NancyFX that is self hosted using Microsoft.Owin.Hosting (so IIS is not used at all) and I need to create a CSR for the production...

Owin WS-Federation setting up token sliding expiration

owin,katana,ws-federation,sts-securitytokenservice
Can somebody explain how to implement sliding expiration using the new Owin WS-Federation plugin? On the client side, at WS-Fedeartion configuration I see that there are some events like : Notifications = new WsFederationAuthenticationNotifications { SecurityTokenReceived = ..., AuthenticationFailed = ..., RedirectToIdentityProvider = ..., MessageReceived = ..., SecurityTokenValidated = .......

OWIN Authentication with Google

asp.net-mvc,authentication,owin
I'm using owin authentication on an ASPNET MVC project. When using google I have the following problem: 1- The user signs in with the google account 2- The user signs out 3- The next time the user tries to sign in, the current google account is automatically used to sign...

The name 'ConfigureAuth' does not exist in the current contex

c#,asp.net-mvc,asp.net-mvc-4,razor,owin
I'm getting Error "The name 'ConfigureAuth' does not exist in the current context " in My Stratup Class . I installed all "AspNet Identity" libraries also using Microsoft.Owin; using Owin; [assembly: OwinStartupAttribute(typeof(project_name.Startup))] namespace project_name { public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); } } } ...

How to serve index.html with web api selfhosted with OWIN

asp.net-web-api,routing,single-page-application,owin
Should be an easy question, just can't find the answer. I have an SPA (AngularJS) with web api which is self hosted with Owin. I use Nancy to serve the page, but I would like to get rid of Nancy and use Index.html as my single page. I've seen this...

Why CreateAsync of AuthenticationTokenProvider Is Called When Request to Exchange RefreshToken Arrives?

asp.net,oauth,owin
I have custom implementation of AuthenticationTokenProvider abstraction. It has two methods to be overriden that I'm using: CreateAsync, ReceiveAsync. In OAuthAuthorizationServerOptions I have RefreshTokenProvider set to my custom AuthenticationTokenProvider implementation. My access tokens expire in 20 minutes. My refresh tokens expire in 24 hours. When access token expires a request...

Enabling https with NancyFx Owin Self-host

ssl,https,owin,nancy
I'm selfhosting a NancyFx service with Owin (on intranet from a Windows 8 machine) and it works fine. Trying to switch to HTTPS but have run into problems. I have: Created self-signed root CA Created exchange-cert using above CA (CN=mycomputer) Exported public key of CA and installed on client-machine Used...

Why changing the status code after writing to the body returns 504?

c#,owin,asp.net-5
In ASP.NET 5 I've seem that the following code gives an error 504 in the response: public class Startup { public void Configure(IApplicationBuilder app) { app.Use((next) => { return async (context) => { context.Response.StatusCode = 200; await context.Response.WriteAsync("Hello World"); context.Response.StatusCode = 201; await context.Response.WriteAsync("Status code changed"); }; }); } }...

Azure Active Directory Assigned Users Ignored

asp.net,asp.net-mvc,azure,active-directory,owin
I have added Azure Authentication to my ASP MVC application by following the guide at https://github.com/AzureADSamples/WebApp-OpenIDConnect-DotNet. It works as far as restricting access to only users that have accounts in the domain. Non users are rejected. However, there is a setting in the Azure Management site that allows you to...

Getting browser information from IOwinContext

.net,asp.net-mvc,owin
How can I get the browser from the IOwinContext? I am attempting to log requests alongside their responses from my owin middleware (code below). public async override Task Invoke(IOwinContext context) { var sw = new Stopwatch(); sw.Start(); var user = context.Authentication.User.Identity.IsAuthenticated ? context.Authentication.User.Identity.Name : "anonymous"; _logger.WriteVerbose( string.Format("{0} {1} '{2}{3}{4}' @...

OwinHost.exe vs Custom Host

c#,asp.net,owin,host,katana
Katana has 3 popular Host: ? IIS/ASP.NET Custom Host OwinHost.exe My question is what is the difference between Custom Host and OwinHost.exe?...

Add Owin Pipeline Middleware after OwinStartup for new Tenant

c#,asp.net-mvc,owin,ws-federation,openid-connect
I have a multi-tenant application where each tenant can define their own ClientID, Authority, etc for either WsFed or OpenIdConnect. All the tenants are registered in the OwinStartup as below: public void Configuration(IAppBuilder app) { List<WsFederationAuthenticationOptions> WsFedTenantOptions = BuildWsFedTenantOptionsList(); List<OpenIdConnectAuthenticationOptions> OpenIdConnectTenantOptions = BuildOpenIdConnectTenantOptionsList(); app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);...

How to link exceptions to requests in Application Insights on Azure?

azure,owin,azure-web-sites,ms-application-insights
We are using Owin on Azure for a REST service, and have to report to Application Insights directly. We want to log exceptions and requests. Right now we have this: using AppFunc = Func<IDictionary<string, object>, Task>; public class InsightsReportMiddleware { readonly AppFunc next; readonly TelemetryClient telemetryClient; public InsightsReportMiddleware(AppFunc next, TelemetryClient...

properly call EF SaveChanges after each request with Autofac managing scope

entity-framework,owin,autofac,middleware
I would like to put in a bit of infrastructure on my project to SaveChanges on my db context at the end of every request. So I create a simple piece of Owin middleware app.Use(async (ctx, req) => { await req(); var db = DependencyResolver.Current.GetService<MyDbContext>(); await db.SaveChangesAsync(); }); This does...

Data caching per request in Owin application

asp.net,owin
In traditional ASP.NET applications (that use System.Web), I'm able to cache data in HttpContext.Current.Items Now in Owin the HttpContext is not available anymore. Is there a way to do the similar thing in Owin - a static method/property through which I can set/get per request data? This question gave some...

Manually dispose OWIN WebApp

c#,asp.net-web-api,unity,asp.net-web-api2,owin
I'm trying to use OWIN to Self-Host Web API while running my tests and I want to start it in BeforeEach and stop in AfterEach methods. All examples, that I found suggests to use using keyword, e.g. using (WebApp.Start<Startup>(url: baseAddress)) { ... } But in my case it doesn't help....

get application path in asp.net vnext

c#,owin,asp.net-5
I've been trying to open a file in asp.net 5 and have not been having a lot of success. In the past you used Server.MapPath or HostingEnvironment.ApplicationPhysicalPath. They are both gone in the OWIN based framework. There is a HostingEnvironment class but it's in the System.Aspnet but it needs to...

Configure a custom store in ASP.NET Identity 2.x

c#,asp.net,configuration,asp.net-identity,owin
I've already developed an implementation to the following ASP.NET Identity interfaces: IUserLoginStore<TUser>, IUserClaimStore<TUser>, IUserRoleStore<TUser>, IUserPasswordStore<TUser>, IUserSecurityStampStore<TUser>. Furthermore, I'm using OWIN/Katana, so I need to configure this by code during startup. How do I provide/configure my custom store implementation to ASP.NET Identity? Note: I've been searching a simple and clear tutorial...

Nuget failing to install OwinHost 3.0.1

.net,nuget,owin,visual-studio-2015
I'm attempting to install the OwinHost 3.0.1 package via nuget on visual studio 2015 CTP 6 and am getting the following error: System.IO.FileNotFoundException: Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. File name: 'System.Management.Automation, Version=3.0.0.0, Culture=neutral,...

Intermittent redirection loops during ADFS authentication

c#,.net,asp.net-mvc-5,owin,ws-federation
I am using Owin to configure my ASP.NET MVC 5 (.NET 4.5, IIS 7/8) application to authenticate against a third-party ADFS setup: app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType }); app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions { Wtrealm = Settings.Auth.Wtrealm, MetadataAddress = Settings.Auth.MetadataAddress }); I also have a...

Send connection string to ApplicationDBContext

c#,asp.net-mvc-5,asp.net-identity,owin
I have customized the ApplicationDBContext class to receive a connection string via its constructor. It can connect to the database OK when called directly however when called through the app.CreatePerOwnContext I am unable to call it. My class definition is below: public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext(string databaseConnection)...

Owin self-host Web API 405 method not allowed on DELETE

web-api,owin,katana,http-status-code-405
I am creating an Owin self-host Web API and getting a 405 method not allowed response when posting a DELETE request the server. POST and GET seem to work with not problems. I can reproduce the error in the ASP.Net Sample application OwinSelfHostSample project at https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OwinSelfhostSample/ReadMe.txt I do not have...

the name configureauth does not exist

c#,model-view-controller,owin
i'm trying this tutorial http://httpjunkie.com/2013/311/adding-mvc-5-identity-to-an-existing-project/ but is shows me an error Error 5 The name 'ConfigureAuth' does not exist in the current context this is my startup.cs class using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.Owin; using Owin; [assembly: OwinStartupAttribute(typeof(TicketSystem.Startup))] namespace TicketSystem { public partial class Startup {...

IIS hosted ASP.NET and SharePoint server libraries - authentication / security issue

asp.net,iis,sharepoint,asp.net-web-api,owin
I am currently working on a project where we are focused to develop as much as possible against the SharePoint CSOM library. Unfortunately CSOM offers no possibility to access Cross-Site-Publishing functionalities. So we decided to deploy a ASP.NET Web API web service on the target SharePoint system, which is hosted...

Api controllers work but web razor controllers don't with owin

c#,asp.net-mvc,asp.net-web-api,owin
I'm getting crazy with this. I'm developing an ASP.NET Web Api 2.2 project with Visual Studio 2012 Premium, .NET Framework 4.5.1 and C#. I have created an empty ASP.NET MVC 5 project. I have deleted Global.asax and create this Startup.cs class: using Microsoft.Owin; using Ninject; using Ninject.Web.Common.OwinHost; using Ninject.Web.WebApi.OwinHost; using...

OWIN Service resolution Using Autofac

dependency-injection,web-api,autofac,owin
I have an WebApi application using OWIN and Autofac. Although controllers and parameters get resolved correctly, I would like to be able to use OwinContext.Get<type> to resolve types registered with Autofac. Is that posible? Already setapp.UseAutofacMiddleware(container); and config.DependencyResolver = new AutofacWebApiDependencyResolver(container); By example, I registered builder.Register<IAppConfiguration>(c => new AppConfig()); and...

Use OWIN to connect an ASP.NET MVC application to Azure AD or use the default templates

asp.net-mvc,azure,asp.net-mvc-5,owin,azure-active-directory
The default templates for Organizational accounts in ASP.NET MVC 5 applications use HttpModules to handle the response from Azure AD and create the corresponding ClaimsIdentity. Looking at the examples for the ADAL library, I saw that it is also possible to use an OWIN middleware for the same purpose. Which...

Using log4net to log unhandled errors when using OWIN

log4net,asp.net-web-api2,owin
Can you point me to some log4net tutorial or samples that logs all unhandled exceptions occurring on my MVC Web Api when using OWIN? I have a Startup class that configures Castle Windsor and OAuth and I'm not sure how application errors are handled for OWIN enabled applications. I have...

Bad Response, Startup Options in OWIN server

c#,web-api,owin
Got some problems with my OWIN selfhost server. I'm trying to make it accessible through my local network. Which means the IP address of the host will be used to connect to the server. Bad thing is, I get a bad request, invalid hostname. I've done some Googling and I...

Asp.net web api with autofac and Hangfire

autofac,owin,hangfire
I recently upgraded to a new version of Hangfire and I am struggeling trying to setup my webapi with autofac and Hangfire. I'm using Autofac Hangfire integration version 1.1 and Hangfire 1.4.2. I'm using Owin to host. I keep getting following error: The requested service 'IFoo' has not been registered....

SignalR - OWIN - Multiple endpoints

signalr,owin,startup
I have a scenario as such. A base class which modules are derived from. Each module has it's own signalr hubs. I want to host all modules in a single host, separated by module name. Some modules will share hub names. namespace domain.com.base { public class BaseClass { public string...

OWIN OpenIdConnect middleware - set RedirectUri dynamically

owin,middleware,openid-connect
Is there any way how can I set RedirectUri property for OpenIdConnectMessage based on a Request scope, not Application scope? My app is serving multiple domains (myapp.com, myapp.fr, ..) and based on domain, it determine default language for the content. I need that the user is taken back to the...

How do I add Ninject Controller Factory to an ASP.NET MVC app with OWIN?

c#,asp.net-mvc,asp.net-web-api,ninject,owin
I'm developing an ASP.NET Web Api 2.2 project with Visual Studio 2012 Premium, .NET Framework 4.5.1 and C#. I have created an empty ASP.NET MVC 5 project. I have deleted Global.asax and create this Startup.cs class: using Microsoft.Owin; using Ninject; using Ninject.Web.Common.OwinHost; using Ninject.Web.WebApi.OwinHost; using Owin; using System.Reflection; using System.Web.Http;...

No IUserTokenProvider is registered when using dependency injection

c#,asp.net-mvc,owin,autofac
I got an error when my GeneratePasswordResetTokenAsync() method is call. I configured autofac with owin identity. The error is : No IUserTokenProvider is registered when using dependency injection In my sample.web project there is a AutofacConfig.cs file where I register signinmanager and usermanager which I created in sample.repository project. AutofacConfig.cs...

ApiController route override not working

c#,asp.net-web-api,routing,owin,self-hosting
I have the problem, that in my Asp.Net OWIN self hosted web service route overriding with the Route-attribute does not work. My initial routing looks like this: string routeTempl = "api/" + EndpointManager.API_VERSION + "/{controller}/{action}/{id}"; // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate:...

Users Principle/Identityis overridden by second browser instance in aspnet identity MVC5

c#,asp.net-mvc-5,owin,aspnet-identity
I am using aspnet identity/owin for authentication/Authorization in my application. Problem when I login using second aplication user from new browser instance while first one is already logged in, second browser is probabily overriding the User principle/identiy obejects. Due to this first browse user is getting logged out as second...

How do I implement an OAuth2 Authorization_Code Flow in Web Api using OWIN Middleware?

asp.net-web-api,oauth-2.0,owin
I'm trying to create a simple proof of concept OAuth enabled application but am stuck on the authorization code implementation. Everywhere I read seems like it goes in one way or another, never actually using the authorization code flow. I've been using the following resources for information: https://tools.ietf.org/html/draft-ietf-oauth-v2-31 https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified http://www.asp.net/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server...

[OAuth2 authorization server]refresh token's expire time need different with access token?

asp.net,oauth,oauth-2.0,owin
I'm learning OAuth2 via this tutorial, then I found refresh token's expire time is the same as access token, is this correct?

How to override default unhandled exception output in Owin?

c#,exception,asp.net-web-api,owin
I've written simple server using Owin Self-hosting and WebApi: namespace OwinSelfHostingTest { using System.Threading; using System.Web.Http; using Microsoft.Owin.Hosting; using Owin; public class Startup { public void Configuration(IAppBuilder builder) { var config = new HttpConfiguration(); config.Routes.MapHttpRoute( "Default", "{controller}/{id}", new { id = RouteParameter.Optional } ); builder.UseWebApi(config); } } public class Server...

Why am I getting “The magic number in GZip header is not correct.” error using OWIN auth against Azure SQL

asp.net-mvc,entity-framework,azure,connection-string,owin
Nothing on Google or SO relates to this specific problem, so asking a new question. I created a brand new Asp.Net MVC Web Application with the standard user-security option. I also created an empty database in Azure. I did nothing but change the default connection string to this: <connectionStrings> <add...

How to mock owin's authorizationManager to test my api controller

c#,unit-testing,mocking,owin,thinktecture-ident-model
I'm using ThinkTecture's resource based authorization in my WebApi. I'm trying to test one of my controller that I needed to check the access inside the function. But now, I can't test the function anymore since, I can't mock an extension method and since it's a nuget method, I can't...

OWIN Startup: Entry point was not found

c#,asp.net-web-api,asp.net-web-api2,owin,katana
The following EntryPointNotFoundException is being thrown in my OWIN Startup configuration upon executing UseWebApi(): An exception of type 'System.EntryPointNotFoundException' occurred in System.Web.Http.Owin.dll but was not handled in user code Additional information: Entry point was not found. Web API configuration: public class WebApiConfig { internal static void Register(HttpConfiguration config) { //...

Can't resolve dependencies in Web Api Controller

c#,asp.net,castle-windsor,web-api,owin
I have a Web Api with owin and Windsor. Get next error: An error has occurred.An error occurred when trying to create a controller of type 'DBManagerController'. Make sure that the controller has a parameterless public constructor.System.InvalidOperationException at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) at...

Temporarily Changing Identity with WebApi 2

c#,asp.net-identity,owin,claims-based-identity
I have a WebApi controller that initially authenticates as a specific WebApi user. Subsequent accesses to the web api will pass a user that operations should be performed as, without having to actually authenticate as that user. I have some services/managers that perform functions as those proper users as part...

Direct login from a link

asp.net,asp.net-mvc-5,owin
I am using asp.net mvc 5 with owin security, and I have to create a link which will be sent to users email. And when user clicks on the link, they will be login to the system directly. I still couldn't figure out how to generate that link with username...

MVC 5 with owin cookie middleware - owinContext.Authentication.sign in not issuing cookies

asp.net,asp.net-mvc,cookies,forms-authentication,owin
I am using MVC 5.2 and am trying to get the Owin cookie middleware working. In my login controller i do the following: public class LoginController { [AllowAnonymous] public ActionResult Login(LoginViewModel loginViewModel) { //authenticate .... var claims = new List<Claim> { new Claim(ClaimTypes.Name, "abc"), new Claim(ClaimTypes.Email, "[email protected]") }; var id...

How to distinguish a mvc 5 response from an web api 2 response?

c#,asp.net-mvc,authentication,asp.net-web-api,owin
my situation is this: I'm working with mvc5 and webapi2 inside the same project. I started working with mvc, and as i needed authentication and authorization features i decided to use identity. Then, because of the changing requirements, i needed to implement a web service, so i decided to use...

Change HTTP response in ASP.NET WebApi

c#,asp.net-web-api,oauth,owin,access-token
I am trying to implement server for issuing web tokens using ASP.NET WebApi. I've found great tutorial on how to do this step by step, and everything is working fine, except I need to change some values in HTTP response. This is a picture of a call where user credentials...

OpenID OWIN auth and lack of user permissions

azure,owin,openid-connect
I may be handling this totally incorrect, but I am using OpenID with MS Azure to authentication my users, then I check to make sure the user has a user account in the notifications of the OpenID middleware, if the user is not found, I am throwing a security exception....

SignInManager.PasswordSignInAsync Throwing Null Object Exception

c#,asp.net-mvc,asp.net-mvc-5,nullreferenceexception,owin
AccountController.cs houses the AccountController class. The Login method of that class is failing. Specifically, var result = await SignInManager.PasswordSignInAsync( model.Email, model.Password, model.RememberMe, shouldLockout: true); within the Login method is throwing System.NullReferenceException. I've verified that model.Email, model.Password, and model.RememberMe are not null. The next step is to dig in to SignInManager,...

Property Injection with Autofac

c#,dependency-injection,asp.net-mvc-5,autofac,owin
I want to use Autofac for property injection. Here's my setup: public partial class Startup { public void Configuration(IAppBuilder app) { var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterType<TeamManagerContext>().PropertiesAutowired(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); app.UseAutofacMiddleware(container); app.UseAutofacMvc(); ConfigureAuth(app); } } BaseController: public class...

How to set the NameClaimType in an application using OWIN security middleware

c#,owin
I have created an OWIN web application that is using OpenId Connect for authentication via Microsoft.Owin.Security.OpenIdConnect. While authentication works, I find that the created ClaimsIdentity.Name member is null. It appears the ClaimsIdentity is expecting the name to be provided in the claim: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name However, Thinktecture IdentityServer v3 provides the name...

How to stop OWIN Startup class for Identity Framework being called for image requests?

c#,asp.net-mvc,owin
Is it possible to stop the Owin Startup class from being called for every request to images within my /Content/Images folder? I am finding that a new DbContext is being newed up for every image request, when there doesn't need to be any authorization checks for images. UPDATE: I just...

signalR self-host with console/windows service examples VS2010

vb.net,visual-studio-2010,signalr,owin,self-hosting
So I have found various bits and pieces about SignalR v2, it appears to be VS2012/2013 (.net 4.5) only. Can anyone supply a server/client example on how to self host in winforms/console/windows service using VS2010 (.net 4). Managed to get SignalR v1 + VS2010 + ASP.NET Chat application to work...

Using Directory Roles for authorization in ASP.NET MVC application using AAD

asp.net-mvc,owin,azure-active-directory
I am working on a ASP.NET MVC 5 app which depends on multi-tenant authentication using Azure Active Directory. I have authorization setup globally by adding AuthorizeAttribute filter. Now I want the app to be accessible only by users who belong to particular Directory Roles (Global Administrators and User Administrators to...

Ninject Owin Request Scope Silently Fails

dependency-injection,ninject,owin
The problem - Ninject kernel is always returning new instances even if they are scoped to the request. -I'm using OWIN with the SystemWeb host package to allow me to use IIS. -The project depends on an API app that has all the necessary Ninject/owin libraries installed. app.UseNinjectMiddleware(CreateKernel).UseNinjectWebApi(config); -Everything worked...

Not handling authentication, but need claims and cookie

asp.net,authentication,cookies,owin
I am creating a new asp.net MVC 5 application. Authentication is handled by a third party using smart cards. Once a user is authenticated by the third party, I am sent the user's unique ID (inside the http header) which I match up against my database in order to find...

ASP.NET MVC Authenticate before controller instantiated

c#,asp.net-mvc,authentication,openid,owin
I have a controller where I am injecting a service interface into the constructor. The service has interfaces injected into its constructor as well. The IoC container (Unity) needs to use information about the user when constructing one of the classes that it returns for a given interface. What is...

Microsoft.Owin.Security.ActiveDirectory library purpose

authentication,owin,katana
I am getting myself familiar with all the stuff related to authentication using active directory (both Azure AD and Windows Server AD). Currently I am inspecting MS Katana project which is based on OWIN specification. There are three libraries and one of them is kind of confusing for me: Microsoft.Owin.Security.ActiveDirectory...

OWIN use SignalR and prevent 'HTTP Error 403.14 - Forbidden'

asp.net,.net,owin,katana
I'm hosting SignalR in an OWIN selfhosted app - in Azure, like so: public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } ... Easy enough, works fine. Exposes /signalr/hubs as expected. What I would like to do is prevent an HTTP 403.14 when someone hits the / url....

How to serve woff2 files from owin FileServer

mime-types,owin,font-awesome,fileserver,woff2
Since font awesome 4.3, they added the fonts as woff2 format. I'm guetting 404ed when trying to serve this file through owin : app.UseFileServer(new FileServerOptions() { RequestPath = PathString.Empty, FileSystem = new PhysicalFileSystem(@"banana") }); How do I serve woff2 mime type files through file server in owin ?...

MVC Removing ApplicationCookie from Response

asp.net-mvc,authentication,cookies,asp.net-identity,owin
In previous MVC projects using forms authentication i was able to strip the authentication cookie from the response using an action filter with the following override. public override void OnResultExecuted(ResultExecutedContext filterContext) { filterContext.HttpContext.Response.Cookies.Remove(FormsAuthentication.FormsCookieName); } I have now switched over to use OWIN based asp.net identity 2.0 and in the same...

Getting HTTP 401.2 Unauthorized when porting old Web Forms to OWIN

c#,asp.net,authentication,authorization,owin
I've followed Require Authentication for all requests to an OWIN application so my code looks like this: public void Configuration(IAppBuilder app) { app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions() { CookieSecure = CookieSecureOption.Never }); app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions() { MetadataAddress =...

User.IsInRole() does not work right after role assignment, but does after re-login

c#,asp.net-mvc,asp.net-identity,owin
In a ASP.NET MVC 5 application I'm using Unity container to create OWIN/Identity objects and resolve all the dependencies. The problem is when I register as a new user and assign him a role like this userManager.AddToRole(user.Id, "NewUser"); ... await userManager.UpdateAsync(user); it actually creates a record in AspNetUserRoles table, but...