SuppressDefaultHostAuthentication in WebApi.Owin also suppressing authentication outside webapi
It seems that it is a good practice, especially when you mix an OWIN-hosted app and a regular one on the same IIS dir, to setup WebApi with the app.Map.
public void Configuration(IAppBuilder app)
{
var configuration = WebApiConfiguration.HttpConfiguration;
app.Map("/api", inner =>
{
inner.UseWebApi(configuration);
});
}
I had all my controllers configured with a "api" prefix route, and I just moved that to the map function instead. Now webapi is running isolated and it works out with the rest of my application. Thanks @PinpointTownes for pointing me in this direction.
Related videos on Youtube
Poul K. Sørensen
https://www.linkedin.com/in/pksorensen/ I can provide you with Azure, D365 and Sharepoint consultants. I work myself with Azure :)
Updated on July 09, 2022Comments
-
Poul K. Sørensen almost 2 years
I am running into a problem with a solution where I used parts from the Visual Studio SPA template for having the Account Controller in WebApi with Oauth Authentication.
app.UseOAuthBearerTokens(OAuthOptions);
Then I in the owin webapi registration is doing
config.SuppressDefaultHostAuthentication();
but this also supresses the default cookie authentication outside the webapi environment. Is this the intention. If so, how can I set up WebApi to supress cookie authentication but its still active accross the environment for other requests?
-
Bart Verkoeijen about 7 yearsThis blog post by Brock Allen details nicely why that is happening.
-
-
Papa Burgundy almost 10 yearsMake sure to install nugget pkg Microsoft ASP.Net Web API 2.2 OWIN. It had everything installed but that...
-
slypete over 9 yearsThe package identifier is
Microsoft.AspNet.WebApi.Owin
-
SomethingOn over 8 yearsWebApiConfiguration is nowhere to be found. I'm using MVC 5 and have Microsoft.AspNet.WebApi.Owin 5.2.3 installed.
-
Poul K. Sørensen over 8 yearsThats not in the scope for this answer - you can also do a app.Map in MVC5 which is the answer. app.Map("/api", inner => {inner.UseMvc()}); But do not that it also changes your actions if you use the MVC part. Create a new question for your problem if this is not enough for your issue.