小编Ste*_*eve的帖子

触发OWIN cookie中间件设置为被动身份验证模式的正确方法是什么?

我一直在关注OAuth 2.0授权服务器示例代码 http://www.asp.net/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server

以及查看mugget包Microsoft.aspnet.identity.samples包(install-package Microsoft.aspnet.identity.samples -Pre)

并且我试图了解被动与活动cookie中间件的工作原理.

在授权服务器示例中,"应用程序"cookie设置为被动.在Identity示例中,"ApplicationCookie"处于活动状态.

当我阅读有关此属性的内容时,它解释了只有在匹配的AuthenticationType请求时才会触发被动中间件.

如果我编辑Microsoft.aspnet.identity.samples中的startup.auth.cs文件并将应用程序cookie设置为被动,然后登录,它似乎验证,但不会登录.

深入研究代码,我看到帐户控制器归结为对SignInHelper.SignInAsync的调用

此方法获得用户的声明权限,即调用:CreateIdentityAsync(user,DefaultAuthenticationTypes.ApplicationCookie)

我显然不理解某些东西,因为根据我的阅读并且可以说,cookie具有与Claim相同的AuthenticationType,但是当调用Authentication.SignIn时,Cookie似乎没有设置并且我返回到主页面,包含注册和登录选项.

要复制该问题,请启动一个新的项目空asp.net应用程序,然后安装Identity示例包,然后将startup.auth.cs的app.useCookieAuthentication更改为:

app.UseCookieAuthentication(new CookieAuthenticationOptions {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            } …
Run Code Online (Sandbox Code Playgroud)

asp.net cookies middleware oauth-2.0 owin

8
推荐指数
1
解决办法
8938
查看次数

如何在启动类中配置Kestrel URL

我试图找出修改kestrel 从Startup类构造函数侦听的URL的正确方法.

更新:除了下面的答案,我已经明白Startup类不是以我想象的方式配置Kestrel.我原以为Startup会创建一个单独的应用程序范围的配置对象,它可以通过约定来定位,但事实并非如此.正如@Tseng所指出的,应用程序和托管的配置是另外一个问题.链接的答案和接受的答案提供了工作示例.

我在Vagrant中创建了一个全新的Ubuntu 14盒子,并根据Microsoft当前的说明安装了ASP.NET Core 1.1:https://www.microsoft.com/net/core#linuxubuntu

我跑了:

  • dotnet new -t web
  • dotnet恢复
  • dotnet运行

默认情况下,它侦听http:// localhost:5000.在Program.cs中,我可以调用app.UseUrls("http://*:5001),这可以改变URL和端口.

我真正想要的是通过在Startup类中添加一个新的JSON设置文件来按照惯例更改URL,所以我按照示例创建了一个hosting.JSON文件(注意:我已经尝试过"server.urls"和"网址"作为关键).

{
  urls: "http://*:5001"
}
Run Code Online (Sandbox Code Playgroud)

在Startup.cs下面添加appsettings.json文件的默认行我添加了.AddJsonFile("hosting.json",可选:false); (可选:false以确保它正在拾取文件)

public Startup(IHostingEnvironment env)
{
  var builder = new ConfigurationBuilder()
  .SetBasePath(env.ContentRootPath)
  .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
  .AddJsonFile("hosting.json", optional: false);
  if (env.IsDevelopment())
  {
    // For more details on using the user secret store see https://go.microsoft.com/fwlink/?LinkID=532709
    builder.AddUserSecrets();
  }

  builder.AddEnvironmentVariables();
  Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)

我已经验证配置构建后设置是否存在,但是当在Program.cs中构建主机时,它没有被选中或使用

public class Program
{
  public static void …
Run Code Online (Sandbox Code Playgroud)

kestrel-http-server asp.net-core

8
推荐指数
1
解决办法
6589
查看次数

在vb.net Webapi项目中缺少request.CreateResponse

我似乎已经找到了问题,但不知道如何修复它,或者我是否可以.

当我创建一个新C# WebAPI项目,并为System.Net.Http我可以访问 添加导入Request.CreateResponse<T>.

当我创建一个新VB.Net WebAPI项目,并为System.Net.Http我所拥有的所有内容添加导入时Request.createODataErrorResponse.

然而,CreateResponse无论如何我都可以忽略智能感知和访问.似乎VB只是没有正确解释各种扩展.

我想修复intellisense,但实际上并不需要它.

谢谢!

史蒂夫

更新 我发现这个论坛帖子在2012年8月回复,解释它已被复制,但似乎尚未修复.

我是新来的,应该关闭吗?

vb.net asp.net asp.net-mvc-4 asp.net-web-api

6
推荐指数
1
解决办法
6037
查看次数