Tag: owin

用于用户管理的Identity Server和web api

我正在为我的项目使用Identity Server3,我目前有一个网站和api受Id服务器保护,这工作正常但是因为我将用户存储在Id Server数据库中我无法真正更改任何用户的数据从网站上更改个人资料图片或任何索赔值。 为了解决这个问题,我正在考虑在IdServer之上创建API,这个API将管理用户,更改密码,检索用户或更改与用户相关的任何内容,我想在示例项目上创建此API我有我的IdServer使用Owin映射。 现在我在/身份路线中有我的idServer public class Startup { public void Configuration(IAppBuilder app) { Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Trace().CreateLogger(); app.Map(“/identity”, idserverApp => { var efConfig = new EntityFrameworkServiceOptions { ConnectionString = “IdSvr3Config” }; var options = new IdentityServerOptions { SiteName = “Identity server”, IssuerUri = ConfigurationManager.AppSettings[“idserver:stsIssuerUri”], PublicOrigin = ConfigurationManager.AppSettings[“idserver:stsOrigen”], SigningCertificate = Certificate.Get(), Factory = Factory.Configure(efConfig), AuthenticationOptions […]

Owin的NullReferenceException

我刚刚将一个项目克隆到一台新机器上,并且我在使用OWIN的MVC站点上获得了一个难以调试的NullReferenceException : [NullReferenceException: Object reference not set to an instance of an object.] Microsoft.Owin.Security.Cookies.d__0.MoveNext() +664 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24 Microsoft.Owin.Security.Infrastructure.d__2.MoveNext() +860 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +427 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22 Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow() +33 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +150 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +42 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +415 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 它发生在之后 [assembly: OwinStartupAttribute(typeof(Website.Startup))] […]

当前上下文中不存在名称“ConfigureAuth”

当我试图运行我的页面时,我收到错误说, 当前上下文中不存在名称“ConfigureAuth” 在我的Stratup课程中。 我确定已安装所有AspNet Identity库。 接下来我需要做什么,试图解决这个问题? 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); } } }

什么是使IIS通过Owin管道开始响应请求的过程?

如果在Visual Studio 2013中创建一个空的ASP.NET Web应用程序项目,请打开包管理器控制台并安装包Microsoft.Owin.Host.SystemWeb 添加具有配置(IAppBuilder应用程序)方法的Startup类,例如: public class Startup { public void Configuration(IAppBuilder app) { app.Run(context => context.Response.WriteAsync(“hello”)); } } 然后运行,你会看到hello出现在浏览器中。 但是,你看一下这个项目,没有任何文件的变化,即web.config,它表明正在使用Owin管道。 更重要的是,如果您具有Startup类但未安装Microsoft.Owin.Host.SystemWeb软件包,则不会运行Startup的Configuration方法。 我怀疑有一个自定义模块和处理程序参与实现所有这些,但无法找到任何有关它的文档。 我能够找到的唯一能够轻微触及这个主题的是这个 。 你是如何通过引用一些dll来改变处理请求的方式的呢?

Web API OWIN启动exception处理

在我的C#Web API中,我正在尝试添加一个全局exception处理程序。 我一直在使用自定义全局ExceptionFilterAttribute来处理exception并返回一个HttpResponseMessage : public override void OnException(HttpActionExecutedContext context) { … const string message = “An unhandled exception was raised by the Web API.”; var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(message), ReasonPhrase = message }; context.Response = httpResponseMessage; } 这适用于处理控制器级别抛出的exception。 但是,在开发期间,由于数据库连接问题,我们从OWIN启动文件中抛出了错误,但是,返回了标准的IISexception,而不是通过全局exception处理程序,并且完整的HTML被返回给我们的API使用者。 我尝试了几种不同的方法来捕获我的OWIN启动中抛出的exception: 自定义ApiControllerActionInvoker : public class CustomActionInvoker : ApiControllerActionInvoker { public override […]

有没有办法将OwinRequest转换为HttpRequestBase?

我正在编写一个Owin Middleware,我需要使用一些遗留代码,它使用HttpRequestBase作为方法参数。 遗留代码不遵循SOLID所以不可能将其扩展为使用OwinRequest而不是HttpRequestBase 是否有将OwinRequest转换为HttpRequestBase的扩展(或方法)?

如何在用户点击注销按钮后让用户登录系统并注销?

我正在使用microsoft asp.net身份的自定义实现,因为我有自定义表,这就是为什么我已经给出了我的所有方法IUserStore和IUserPasswordStore的自定义实现。 问题是当用户登录然后在10-15分钟后登录用户会话到期但我想要的是除非用户注销我想让用户登录系统。 码: public partial class Startup { public void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext(ApplicationUserManager.Create); app.CreatePerOwinContext(ApplicationSignInManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Account/Login”), Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); } } 账户管理员: [Authorize] public class AccountController : […]

Owin SelfHost WebApi – 客户端在响应期间关闭连接会引发exception吗?

我正在运行一个基于Owin Selfhost的WebApi,我在其中放入了一个API未处理的exception记录器 config.Services.Add(typeof(IExceptionLogger), _apiExceptionLogger); ApiExceptionLogger的相关部分: public override void Log(ExceptionLoggerContext context) { if (context == null || context.ExceptionContext == null) return; Logger.Error(“Unhandled exception from Web API”, context.ExceptionContext.Exception); } 它定期捕获和记录的情况是客户端请求数据集然后在结果(JSON)被发送回来时关闭连接的人 – 在chrome中发出请求的人,然后在所有结果返回之前点击X按钮: P 为了完整性,我在下面粘贴了一个堆栈跟踪,只想知道两件事: 这是常规/预期的行为吗? AFAIK是……我正在运行一个非常默认的API和管道 有没有办法处理这个? 基本上在取消的情况下更优雅地停止请求处理(在整个请求管道中记录的取消令牌确实浮现在脑海中,但在这种情况下它们看起来并不像在所有令牌仅支持合作取消之后) 我没有深入研究套接字级别发生的事件序列,到目前为止,这只是一个日志记录麻烦。 System.Net.Http.HttpRequestException: Error while copying content to a stream. —> System.IO.IOException —> System.Net.HttpListenerException: The I/O operation has been aborted […]

OWIN app.use vs app.run vs app.map

Owin中的app.use , app.run , app.map什么区别? 什么时候用? 阅读文档时并不简单。

创建为.Net Auth Cookie交换自定义令牌的Owin Auth Provider

我正在尝试在2 .Net应用程序之间创建类似SSO的解决方案.Net app 1有一个自定义令牌生成器和端点来validation返回用户信息的令牌。 .Net应用程序2使用Owin进行保护,是一个典型的独立应用程序,用户可以使用密码和用户名直接登录。 我创建(基于Passion for Coding Blog和Github )一个自定义Owin提供程序,它可以在Authorization标头中查找标记,也可以从用户从.Net App 1单击链接并发送到的链接中查找参数.Net App 2查询字符串中的令牌与GET一样(我知道这不安全,我们最终将使用OpenID来获取它的价值,我们只需要这个演示)。 我能够获得令牌validation它并创建一个身份并进行身份validation我不能让提供者创建一个.Net Auth Cookie,以便后续请求得到身份validation而不会出现401错误。 处理程序文件: using Microsoft.Owin.Infrastructure; using Microsoft.Owin.Logging; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Infrastructure; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Security.Claims; using System.Text; using System.Threading.Tasks; namespace SomeOAuth { // Created by the […]