Tag: owin

ASP.NET MVC 5 Web.config:“FormsAuthenticationModule”或“FormsAuthentication”

好吧,这不是什么大不了的事情,但是这让我烦恼,我不能放过它。 所以我使用.NET 4.5.1和OWINauthentication使用MVC 5.1。 所以当你创build一个新的MVC 5项目时,下面的内容会自动添加到Web.config中去除表单validationhttp模块,因为在使用OWIN中间件时不再需要它: <system.webServer> <modules> <remove name="FormsAuthenticationModule" /> </modules> </system.webServer> 现在,我们正在删除模块,这意味着它已经被添加,所以这里是在C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config注册这个http模块的条目: <httpModules> <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" /> </httpModules> 这里是IIS 8.5的C:\Windows\System32\inetsrv\config\applicationHost.config的条目,告诉我的应用程序使用该模块: <system.webServer> <modules> <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition="managedHandler" /> </modules> </system.webServer> 因此,在应用程序级别自动添加到我的Webconfiguration中的名称属性为“FormsAuthenticationModule”,而两个服务器级别/ asp.net级别configuration文件中的条目使用名称属性“FormsAuthentication”。 那么这里发生了什么? 在我看来,该模块将不会被删除,因为name属性不匹配。 我只是认为这是一个错字,但是在网上search之后,每个人似乎都在应用程序web.config中使用“FormsAuthenticationModule”。 这是新版本的asp.net / iis最近的变化还是我错过了什么?

红隼和武士刀之间的区别

我的理解是,你现在可以使用Katana自己托pipeWebAPI,并且MVC将在未来的版本中具有这种能力。 本质上Katana将是一个可用于MVC和WebAPI的托pipe选项。 Kestrel已经进入了图片,我看到一些MS员工在博客上展示了在Linux上托pipeASP.NET vNext。 我的理解是Kestrel和Katana都实现了OWINpipe道。 从那里,这是一点点模糊。 我问自己,为什么Kestrel进入图片,看起来Katana可以达到相同的目的,如果你编写单声道,并做了一些努力,使其跨平台兼容(可能说起来容易做起来)。 Kestrel和Katana服务于同样的目的吗? 或者是一个专门从事某种方式,另一个不是? Kestrel最终将成为Windows部署的可行select吗? 或者将它专门用于非Windows环境,Katana仍然是Windows的select? 我认识到我可能会要求一个苹果比较桔子,因为我不知道武士刀/红隼,但如果答案是“橙子比苹果有更多的酸性味道”,那么国际海事组织是一个完全有效的答案。

Web API 2 OWIN不记名令牌的用途是什么?

我想了解MVC 5中的单页面应用程序模板中的新OWIN承载令牌authentication过程。如果我错了,请更正我的OAuth密码客户端authenticationstream程,承载令牌authentication通过检查httpauthentication请求标头对于承载访问令牌代码来查看请求是否经过authentication,它不依赖于cookie来检查特定的请求是否被authentication。 根据这个职位: 使用Web API示例的OWIN承载令牌authentication public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { using (IdentityManager identityManager = _identityManagerFactory.CreateStoreManager()) { if (!await identityManager.Passwords.CheckPasswordAsync(context.UserName, context.Password)) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } string userId = await identityManager.Logins.GetUserIdForLocalLoginAsync(context.UserName); IEnumerable<Claim> claims = await GetClaimsAsync(identityManager, userId); ClaimsIdentity oAuthIdentity = CreateIdentity(identityManager, claims, context.Options.AuthenticationType); ClaimsIdentity cookiesIdentity = CreateIdentity(identityManager, claims, […]

login页面在不同的域

我对OWINauthentication是完全陌生的,而且我一定是误解了一切工作,但是在任何地方我都找不到这个。 我想要的只是能够使用中央域进行身份validation。 如果有人在未经身份validation的情况下尝试访问apps.domain.com ,则会将其redirect到accounts.domain.com/login以便将所有身份validation分为自己的域和应用程序。 使用MVC 4表单身份validation非常简单,您可以指定完整的URL,但似乎并不在OWIN中。 在Startup.Auth.cs : app.UseCookieAuthentication(new CookieAuthenticationOptions { LoginPath = new PathString("/account/login") } 使用CookieDomain选项设置Cookie时,指定域名很容易。 但是,当您指定要redirect到的loginpath时,必须相对于当前的应用程序,那么如何在MVC 4表单身份validation中完成如此简单的操作呢? 没有深入到OWINauthentication是什么,在search几个小时后,我找不到任何解决这个问题的东西。

如何将我的Autofac容器插入到ASP中。 NET身份2.1

我一直在研究ASP.NET Identity 2.1新版本的新function,其中一个增强function是集成到OWIN中间件中的新IoCfunction。 我在例子中看到的一个句子是这样的: app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 这个句子接收一个函数委托,它返回一个在例子中提供的pipe理器实现的新实例: public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) { var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>())); 我个人不喜欢这个实现,因为我不能使用容器来为这些pipe理者注入任何依赖。 另外还有一个“IdentityFactoryOptions”和一个“IOwinContext”,它们被“神奇地”注入到了Im不能够拉入我的IoC容器的函数中。 有没有人有这个实施更好的解决方法?

在ASP.NET Web API 2中禁用* all *exception处理(为我自己腾出空间)?

我想在中间件组件中连接exception处理,如下所示: public override async Task Invoke(IOwinContext context) { try { await Next.Invoke(context); } catch (Exception ex) { // Log error and return 500 response } } 然而,我想捕捉到的一些exception是在Web APIpipe道被捕获并转换为HttpErrorResponse之前,我可以find它们。 在这个过程中,我失去了很多关于错误的细节,所以在debugging时我不能获得有用的堆栈跟踪信息(debugging程序甚至在引发exception时都不会停止 – 我必须手动执行代码并查看那里失败…)。 我尝试添加一个自定义exception处理程序与以下实现: public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken) { var owinContext = context.Request.GetOwinContext(); owinContext.Set(Constants.ContextKeys.Exception, context.Exception); return Task.FromResult(0); } 通过config.Services.Replace(typeof(IExceptionHandler), new MyExceptionHandler());注册config.Services.Replace(typeof(IExceptionHandler), new MyExceptionHandler()); 在我的启动configuration,但通过执行Next.Invoke(context)后,看着它 context.Get<Exception>(Constants.ContextKeys.Exception); […]

在Windows服务中使用OWIN托pipeWebAPI

我使用OWIN自己托pipe的Web API(在Windows服务中)。 据我所知,这足以使HTTP请求来到Windows服务。 我可以在本地(从同一台机器)访问WebAPI URL( http://localhost/users ),但不能从其他机器访问。 我正在使用端口80, IIS停止 。 其他网站(托pipe在IIS中,在端口80上)在IIS运行时正常工作。 //在Windows服务中: public partial class Service1 : ServiceBase { … … protected override void OnStart(string[] args) { Console.WriteLine("Starting service…"); string baseAddress = "http://localhost:80/"; WebApp.Start<Startup>(baseAddress); //This is OWIN stuff. } … … } public class Startup { // This code configures Web API. The Startup class […]

MVC 5如何用本地化路线定义Owin LoginPath

我有一个MVC 5网站与本地化的路线定义为 routes.MapRoute( name: "Default", url: "{culture}/{controller}/{action}/{id}", defaults: new { culture = CultureHelper.GetDefaultCulture(), controller = "Home", action = "Index", id = UrlParameter.Optional } ); 默认文化的结果是"en-US" 。 问题出现在启动时,我必须使用LoginPath属性定义loginURL,该属性被设置一次,它将始终使用提供的值,例如,如果“/ en-Us / Account / Login”是指定值。 然后我尝试着使用UrlHelper类来体验一些魔法的希望,但是结果显然是一样的: var httpContext = HttpContext.Current; if (httpContext == null) { var request = new HttpRequest("/", "http://example.com", ""); var response = new HttpResponse(new StringWriter()); […]

OWIN和Katana,为什么从服务器上分离应用程序?

我不完全得到这个..确定它很酷,能够自我托pipe一个应用程序,这可能是很好的,因为如果IIS出于任何原因下降…那么所有的网站宕机..但如果他们是自我的,托pipe,然后他们住在那里自己的生活有自己的背景下..我认为是好的..但我仍然没有得到这个优点..我在IISpipe道中跳过很多不必要的东西,通过使用owin加快应用程序,或者..什么是实际的优点? (你不需要列出所有这些,如果他们很多:),但只是这样我得到你为什么想要在IIS上使用OWIN和Katana) 提前致谢!

在自主托pipe的OWIN Web API中,如何在closures时运行代码?

我使用以下代码片断自主托pipeOWIN Web API: class Startup { public void Configuration(IAppBuilder appBuilder) { var config = new HttpConfiguration(); var route = config.Routes.MapHttpRoute("DefaultApi", "{controller}"); appBuilder.UseWebApi(config); } } WebApp.Start<Startup>("http://localhost:8080") 我想在我的Web API服务closures时运行一些代码。 我正在寻找像HttpApplication.Application_End ,一个Disposed事件,或一个妥善放置override void Dispose() 。 如何在Web API服务closures时运行代码?