katana

Pass command-line arguments to Startup class in ASP Core

你说的曾经没有我的故事 提交于 2019-11-30 22:26:39
问题 I have arguments passed in via the command-line private static int Main(string[] args) { const string PORT = "12345" ; var listeningUrl = $"http://localhost:{PORT}"; var builder = new WebHostBuilder() .UseStartup<Startup>() .UseKestrel() .UseUrls(listeningUrl); var host = builder.Build(); WriteLine($"Running on {PORT}"); host.Run(); return 0; } One of these arguments is a logging output directory. How do I get this value into my Startup class so I can write out to this directory when I

Why does the ASP.NET SPA template instantiate UserManager once for all requests?

…衆ロ難τιáo~ 提交于 2019-11-30 15:44:04
问题 I'm using the VS2013 ASP.NET SPA template as a starting point for my web application which uses the new ASP.NET identity framework. This is from the template: public partial class Startup { static Startup() { UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>()); .... } So, since no DbContext is being passed into the UserStore constructor above, that indicates to me that a new DbContext is being created. Since I also wanted to make use of the data context

Why does the ASP.NET SPA template instantiate UserManager once for all requests?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 15:14:12
I'm using the VS2013 ASP.NET SPA template as a starting point for my web application which uses the new ASP.NET identity framework. This is from the template: public partial class Startup { static Startup() { UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>()); .... } So, since no DbContext is being passed into the UserStore constructor above, that indicates to me that a new DbContext is being created. Since I also wanted to make use of the data context (for other data operations during the request), I changed the template code slightly: public partial class

How do I get an instance of IAppBuilder elsewhere in my ASP.NET MVC 5.2.3 application?

巧了我就是萌 提交于 2019-11-30 12:12:16
I need to build an Owin middle-ware object but not from within the Startup class. I need to build it from within anywhere else in my code, so I need a reference to the AppBuilder instance of the application. Is there a way to get that from anywhere else? You could simply inject AppBuilder itself to OwinContext . But since Owin context only supports IDisposable object, wrap it in IDisposable object and register it. public class AppBuilderProvider : IDisposable { private IAppBuilder _app; public AppBuilderProvider(IAppBuilder app) { _app = app; } public IAppBuilder Get() { return _app; } public

When should I use OWIN Katana?

佐手、 提交于 2019-11-30 10:03:09
问题 I am new to OWIN and Katana. I really don't get why I should use OWIN, while I can use IIS . To simplify, my question is: What do I lose if I skip learning OWIN and use IIS for my websites? I googled but there is not a simple explanation. There is some information here, but they use some jargon phrases so I cannot understand it. 回答1: In asp.net WebApi v2, the OWIN pipeline becomes the default. It is eventually going to be the standard pipeline under any asp.net project. I cannot put it better

Access token revocation implementation in OAuth 2

不羁的心 提交于 2019-11-30 09:25:01
I've used OWIN OAuth 2 to implement my Authorization Server Provider. Now, I want to implement token revocation (when my client application wants to logout). Can anybody help me and tell how to implement token revocation in OWIN KATANA OAuth 2. Are there some good practices for it? There are two kinds of token involved in OAuth 2.0. One is access token and the other is refresh token. For refresh token, I really recommend Token Based Authentication using ASP.NET Web API 2, Owin, and Identity written by Taiseer Joudeh. He provides a step by step tutorial on setting up token based authentication,

Owin, pass custom query parameters in Authentication Request

↘锁芯ラ 提交于 2019-11-30 04:58:55
We have our own OpenID Connect Provider. We want to pass custom query parameter in Authentication request using Owin middleware. And we cannot find the way how to implement this using Microsoft.Owin.Security.OpenIdConnect assembly. Even We cannot find how to add a standard request parameter to Authentication Request (e.g. " login_hint parameter"). For example Google has " login_hint " and " hd " parameters ( https://developers.google.com/accounts/docs/OAuth2Login#sendauthrequest ), and we want to have almost the same parameters. But we even cannot find how to send these parameters to Google

How to set default static web page for Katana/Owin self hosted app?

一笑奈何 提交于 2019-11-30 04:53:26
I've set up a web site using an Owin self hosted console app. I'm serving static files with no problem, the 'root' of the static part of the site works properly, and the web API routes work fine also. If I browse to: http://localhost/index.html it presents everything like I expect. But I have not figured out how to set it so that browsing to: http://localhost presents index.html (as the default view). This Just Works under an IIS-style site. How do I make it work with Owin self host? I do it this way: var physicalFileSystem = new PhysicalFileSystem(webPath); var options = new FileServerOptions

Changing the response object from OWIN Middleware

寵の児 提交于 2019-11-30 02:58:13
My OWIN middleware is like this. (Framework is ASP.NET Web API). public class MyMiddleware : OwinMiddleware { public MyMiddleware(OwinMiddleware next) : base(next) { } public override async Task Invoke(OwinRequest request, OwinResponse response) { var header = request.GetHeader("X-Whatever-Header"); await Next.Invoke(request, response); response.SetHeader("X-MyResponse-Header", "Some Value"); response.StatusCode = 403; } } Questions: Is it the recommended practice to derive from OwinMiddleware ? I see that in Katana source, some of the middleware classes derive from OwinMiddleware and some do

How to use Swagger as Welcome Page of IAppBuilder in WebAPI

允我心安 提交于 2019-11-29 23:59:40
I try to use Swagger with Microsoft WebAPI 2. For the moment, I've the following call in a method. appBuilder .ConfigureOAuth() .UseWebApi(configuration) .UseWelcomePage(); If I want to use Swagger, I must use this url " https://localhost:44300/swagger " which one works very well. I want my home page redirects to the url of my swagger, perhaps as follows but this sample doesn't works. appBuilder ... .UseWelcomePage("/swagger"); Any idea ? I got this working how I wanted by adding a route in RouteConfig.cs like so: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("