我有一个Web API消息处理程序MyHandler,我想在OWIN管道中作为中间件运行.所以像这样配置处理程序.
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseHttpMessageHandler(new MyHandler());
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
"DefaultWebApi",
"{controller}/{id}",
new { id = RouteParameter.Optional });
app.UseWebApi(config);
}
}
Run Code Online (Sandbox Code Playgroud)
处理程序非常简单,什么都不做.
public class MyHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{ // <--- breakpoint here
var response = await base.SendAsync(request, cancellationToken);
return response;
}
}
Run Code Online (Sandbox Code Playgroud)
我在里面放了一个断点SendAsync,它确实打破但是下面的base.SendAsync炸弹默默地看着我A first chance exception of type 'System.InvalidOperationException' occurred in System.Net.Http.dll.
我可以很容易地添加 …
我很想知道IIS在应用程序生命周期中如何调用OWIN管道.
我试图了解这一点并发现它Microsoft.Owin.Hosting.SystemWeb对此负有责任,但解释这一点的图表对我自己和其他愿意了解OWIN的人非常有帮助.
关于OWINHost,我能够弄清楚OwinHost如何设置主机然后调用其他OMC等.
另外,我有兴趣了解我们内置的HttpModule如何与OWINHost和IIS托管一起使用.
通过网络过滤后,我对这些东西感到困惑和疑惑.合适的指针或文档将有很大帮助.
链接提到:
我刚开始努力去理解owin和katana.在Asp.Net教程之后,
我在VS2013中创建了一个空白的asp.net项目,并添加了一个Nuget Package引用Microsoft.Owin.Host.SystemWeb.我创建的项目是空白,如图所示.

这包含什么,除了AssemblyInfo.cs,Web.config和packages.config.现在当我跑(F5)时,它说
- 找不到包含OwinStartupAttribute的程序集.
- 找不到包含Startup或[AssemblyName] .Startup类的程序集.要禁用OWIN启动发现,请在web.config中添加值为"false"的appSetting owin:AutomaticAppStartup.要指定OWIN启动程序集,类或方法,请在web.config中添加appSetting owin:AppStartup以及完全限定的启动类或配置方法名称.
现在问题是如何通过添加一个Nuget引用Microsoft.Owin.Host.SystemWeb,它开始寻找像Owin一样特有的东西Startup,如错误消息中所示的那样?我的意思是我运行了一个没有Nuget引用的不同项目,错误信息完全不同.没有什么似乎至少在两个文件改变AssemblyInfo.cs,Web.config通过添加的NuGet参考.据我所知,添加Nuget添加了一个packages.config文件并添加了一些项目引用.此外,我还通过选项卡比较了两个项目选项卡的项目属性,但我没有发现任何差异!所以我想知道世界上是什么导致Owin项目寻找Startup类?
Asp.Net vNext是主机不可知的,应用程序可以在许多平台上托管,符合OWIN标准.根据我从开发人员那里得到的讨论,典型的vNext应用程序可以使用webListener和单独的控制台应用程序进程托管在Helios,Kestrel上.
我提出这个问题的意图是,如果我必须解释所有这些与当前Asp.Net开发人员之间的区别,我将如何解释它?背后的技术细节是什么?
有一种简单的方法可以使用一种全局错误陷阱来记录OWIN托管Web API中的所有未处理错误吗?有点像在Global.asax中声明全局错误陷阱时.我必须说Microsoft.Owin.Logging命名空间的文档很薄.
我在这里检查了OWIN上的这些优秀样品.但我仍然需要捕获异常并调用记录器.
使用单个 asp.net(4.6.1) web 项目,显然我无法验证在同一台服务器上生成的 jwt 令牌。
启动.cs:
var secret = Encoding.UTF8.GetBytes("12341234123412341234");
var jwtFormatter = new CustomJwtFormat("Any", "local", secret);
// This part checks the tokens
app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
AuthenticationMode = AuthenticationMode.Active, // Block requests
AllowedAudiences = new []{"Any"},
TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new InMemorySymmetricSecurityKey(secret),
ValidAudience = "Any",
ValidIssuer = "local"
}
});
// This part issues tokens
app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = false,
TokenEndpointPath = new PathString("/auth"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
Provider = new CustomOAuthProvider(), …Run Code Online (Sandbox Code Playgroud) 在此处找到演示此问题的完整示例应用.
我正在尝试使用OWIN中间件来填充WebForms页面可以访问的静态标识符,但我注意到某些类型的行为不直观 - 特别是AsyncLocal<T>.
考虑以下工作示例,使用int:
简单的静态容器
public static class Container
{
public static int CallId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
简单的OWIN配置
[assembly: OwinStartup(typeof(Startup))]
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
Container.CallId = 5;
return next.Invoke();
});
}
}
Run Code Online (Sandbox Code Playgroud)
简单Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Container.CallId != 5)
{
throw new Exception("What happened to CallId");
}
}
Run Code Online (Sandbox Code Playgroud)
这按预期运行.中间件设置CallId为5,WebForms页面看到5.不抛出异常.
这是事情打破直觉的地方,如果我想使用AsyncLocal<int>我的CallId,那么WebForms页面中的值就不再可用了 …
从最近的版本和下面的对话来看,现在 Katana(4.1.0) 支持带有自动代码兑换的代码流(这意味着我们没有显式调用 tokenendpoint 来兑换 idtoken、accesstoken 等代码)
https://github.com/aspnet/AspNetKatana/pull/297
所以,我已经升级了 Katana dll 并且有 p
Notifications = new OpenIdConnectAuthenticationNotifications()
{
RedirectToIdentityProvider = OnRedirectToIdentityProvider,
//MessageReceived = OnMessageReceived, -- previous I were calling token endpoint in this notification
SecurityTokenReceived = notification => Task.FromResult(0),
SecurityTokenValidated = OnSecurityTokenValidated,
AuthenticationFailed = OnAuthenticationFailed,
AuthorizationCodeReceived = AuthorizationCodeReceived, -- added this notification per latest improvements
TokenResponseReceived = TokenResponseReceived
}
Run Code Online (Sandbox Code Playgroud)
以及这里的实现
private Task AuthorizationCodeReceived(AuthorizationCodeReceivedNotification arg)
{
return Task.FromResult(0);
}
Run Code Online (Sandbox Code Playgroud)
我期望中间件调用令牌端点来兑换授权代码,但这不会发生。
我在这里错过了什么吗?我应该在此处添加一些代码以便中间件兑换代码吗?请各位指教..
更新:
我按照其他博客设置如下,
args.App.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
//other properties removed for …Run Code Online (Sandbox Code Playgroud) 我想在我的SPA WEBAPI应用程序中使用OWIN使用Facebook-SDK登录弹出窗口.VS 2013已经为facebook登录提供了一个很好的模板,但它高度依赖于我不喜欢的服务器端代码.通过使用Facebook-SDK,我可以登录到facebook并访问user_id,access_token等,在此之后,我将access_token发送到/ signin-facebook?code = [access_token],但是,我得到access_denied错误.我想这是因为我干预了owin工作流程并且不发送相关cookie.
总而言之,如果我已经拥有access_token ,是否可以绕过此图片中登录流程中的前3个步骤?
facebook-javascript-sdk asp.net-web-api single-page-application owin katana
我正在构建一个使用cookie身份验证作为主要身份验证方法的MVC 5 Web应用程序.
我们的申请流程如下:
问题是,实现访问令牌验证,到期和续订的最佳位置是什么.如果有人能引导我走向正确的方向,我真的很感激.
var googleCreds = new GoogleOAuth2AuthenticationOptions
{
ClientId = "833250754551-qg564a5g29f0l37q0egqimcoklpjf6dj.apps.googleusercontent.com",
ClientSecret = "YpY_u07KQU4kjhPWH5vuiMzz"
Provider = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationProvider
{
OnApplyRedirect = context =>
{
var queryString = HttpContext.Current.Request.QueryString.ToString();
var queryParms = HttpUtility.ParseQueryString(queryString);
string redirect = context.RedirectUri;
redirect += "&access_type=offline";
redirect += "&approval_prompt=force";
redirect += "&include_granted_scopes=true";
var uri = new Uri(redirect);
if ((!string.IsNullOrEmpty(queryParms.Get("scope"))))
{
var scope = queryParms.Get("scope");
var redirectQueryString = HttpUtility.ParseQueryString(uri.Query);
switch (scope)
{
case "GooglePlus":
redirectQueryString.Set("scope", "https://www.googleapis.com/auth/plus.login");
break; …Run Code Online (Sandbox Code Playgroud)