小编Zap*_*ica的帖子

SignInManager 在尝试登录时抛出 null

我正在实施 asp.net 身份。我已经用int主键而不是默认的String. 我按照以下文章这样做:文章

抱歉所有的代码,但是我已经被这个愚蠢的错误困住了一段时间,所以我宁愿提供更多的信息而不是更少的信息。

我有以下课程:

public class FskUser : IdentityUser<int, FskUserLogin, FskUserRole, FskUserClaim>
{
    ...
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<FskUser, int> manager)
    {
                    // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的自定义登录管理器

  public class FskSignInManager : SignInManager<FskUser,int>
{
    public FskSignInManager(FskUserManager userManager, IAuthenticationManager authenticationManager)
        : base(userManager, authenticationManager)
    {
    }

    public override Task<ClaimsIdentity> CreateUserIdentityAsync(FskUser user)
    {
        return user.GenerateUserIdentityAsync((FskUserManager)UserManager); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc-4 owin asp.net-identity-2

7
推荐指数
1
解决办法
4704
查看次数

Swagger UI 挂在“正在获取资源列表:请稍候”

我正在尝试在我的ASP.NET WEB API 2项目中安装 Swagger API 。

我已经安装了swashbuckle( v5.4.0 ) nuget 包。然后我调试项目并到达URL/swagger/ui/index 我得到的地方Fetching resource list: http://localhost:44432/swagger/docsv1; Please wait. 一段时间后,我的 chrome 页面没有响应。杀死或等待屏幕。

我正在使用默认SwaggerConfig.cs.

我已经在以下位置运行了 json 验证测试: https://online.swagger.io/validator/debug?url={SwaggerJSON URL HERE}/docs/v1

我可以采取哪些步骤来进一步调试我的问题?

[编辑] 我不小心打开了我的一个选项卡,30 分钟后页面呈现。什么可能导致这种情况?解析json文件时可能会无限递归?

swagger swagger-ui asp.net-web-api2

7
推荐指数
1
解决办法
4792
查看次数

Android以这种格式获得时间`yyyy-mm-dd hh:mm:ss`

我希望以下列格式获取设备上的当前时间:2013-10-17 15:45:01?

服务器以字符串形式向我发送上述格式的对象的日期.现在我想获取手机当前时间,然后检查是否有超过5分钟的差异?

所以A:我如何在这个fomat中获得设备的当前时间: 2013-10-17 15:45:01

B我怎样才能弄清楚两者之间的区别.

time datetime android date

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

ViewPager中的SwipeRefreshLayout

我有一个由工具栏和视图寻呼机组成的活动.其布局如下:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="112dp"
    android:layout_gravity="bottom"
    tools:context=".Rhino68PanelActivity" />

<LinearLayout
    android:id="@+id/toolbarContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar" />

    <include
        android:id="@+id/tap_strip"
        layout="@layout/tab_strip" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

然后我将两个片段加载到视图寻呼机中.每个片段包含在它自己的SwipeRefreshLayout.我将展示一个片段布局:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="12"
    tools:context=".Rhino68PanelActivity$DummySectionFragment">
    ...        
  <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView_panel_status"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

现在,当我运行活动时,它似乎工作.但是我注意到我是水平滑动(即转到下一个标签).它会触发swipeRefreshLayoutOnRefreshListener

     mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mSwipeRefreshLayout.setRefreshing(true);
                DoUpdate();
            }
        });
Run Code Online (Sandbox Code Playgroud)

当我尝试刷新时,我也会遇到奇怪的视觉行为.加载标志(旋转圆圈)通常不会显示,有时会显示但仍然很小.我不确定这是否也是导致两种观点相互冲突的原因.

有什么方法可以解决这个问题.我不确定如何.也许通过将SwipeRefreshLayout限制为仅侦听垂直滑动?

任何建议将不胜感激.

android android-viewpager onscrolllistener swiperefreshlayout

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

如何将参数传递给IEventProcessor的实现

我正在忙着EventProcessorHost为一个天蓝色的EventBus客户端实现一个客户端.

我有一个实现IEventProcessor如下的类:

 public class MyEventProcessor : IEventProcessor
    {
        Stopwatch checkpointStopWatch;            

        //TODO: get provider id from parent class     


        public async Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            Debug.WriteLine("Processor Shutting Down. Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason);
            if (reason == CloseReason.Shutdown)
            {
                await context.CheckpointAsync();
            }
        }

        public Task OpenAsync(PartitionContext context)
        {
            Debug.WriteLine("SimpleEventProcessor initialized.  Partition: '{0}', Offset: '{1}'", context.Lease.PartitionId, context.Lease.Offset);
            eventHandler = new MyEventHandler();
            this.checkpointStopWatch = new Stopwatch();
            this.checkpointStopWatch.Start();
            return Task.FromResult<object>(null);
        }

        async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
        {
            foreach …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-eventhub event-processor-host

6
推荐指数
2
解决办法
2906
查看次数

实体框架可查询的多个.Where()子句

我正在尝试使用Entity Framework实现复杂的过滤器:我想where根据我提供的搜索条件向可查询对象添加子句.

我可以在Entity Framework 6中执行以下操作吗?

var queryable = db.Users.Where(x => x.Enabled && !x.Deleted);
// Filter
var userId = User.Identity.GetUserId();
queryable.Where(x => x.AspNetUser.Id == userId);
queryable.Where(x => x.Status >= 2); 
// ...etc
Run Code Online (Sandbox Code Playgroud)

我知道我能做到:

var queryable = db.Users
 .Where(x => x.Enabled && !x.Deleted)
 .Where(x => x.AspNetUser.Id == userId)
 .Where(x => x.Status >= 2); 
Run Code Online (Sandbox Code Playgroud)

但是我没有得到这个解决方案的预期结果.它似乎忽略了秒的两个where条款.

c# entity-framework entity-framework-6

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

Azure 通知中心静态实例或重新创建

使用 C# Azure 通知中心客户端的正确方法是什么?

我们在使用率非常高的服务器中使用它,每天发送数百万次推送。

我想知道我们是否应该NotificationHubClient每次都重新创建它,或者我们是否应该保留它的静态/单例实例,然后每次都重用它?

    /// <summary>
    /// Get refence to the azure hub
    /// </summary>
    /// <returns></returns>
    private static NotificationHubClient GetHub(NotificationHub nhub, bool enableTestSend = false)
    {          
        return NotificationHubClient.CreateClientFromConnectionString(nhub.EndPoint, nhub.HubName, nhub.AllowDiagnosticSend && enableTestSend);
    }
Run Code Online (Sandbox Code Playgroud)

目前,我们每次发送推送通知时都会重新创建它。然而,从个人经验来看,我们在 .net HTTP 客户端上遇到了问题,它释放 tcp 套接字的速度不够快。我担心这个图书馆可能会开始出现类似的问题。

c# azure push-notification azure-notificationhub

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

@ Url.action()的ASP.NET MVC帖子

我有asp.net自动生成的以下控制器

    //
    // POST: /Account/LogOff
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult LogOff()
    {
        AuthenticationManager.SignOut();
        return RedirectToAction("Index", "Home");
    }
Run Code Online (Sandbox Code Playgroud)

现在我有一个注销按钮.目前它看起来像这样:

   <div class="userdrop">
                <ul>
                    <li><a href="@Url.Action("Manage", "Account")">Profile</a></li>                       
                    <li><a href="@Url.Action("LogOff", "Account")">Logout</a></li>
                </ul>
            </div><!--userdrop-->
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我猜它是因为它是一个Post动作方法.

我怎么去"退出"?

[编辑]

为什么它会自动生成为Http Post?这样更安全吗?它在注销时是否不随身携带cookie?

asp.net asp.net-mvc html-helper

5
推荐指数
2
解决办法
3万
查看次数

使用实体框架在现有数据库中实现asp.net Identity

我正在尝试更新旧的网站。它已经具有一个带有用户和角色表的现有数据库,其中包含现有数据。

我需要创建一个新的Web-api和一个新的Web项目,并将ASP.NET Identity集成到现有数据库中。

目前,我已经设置了解决方案来分解项目,如下所示:

  • 服务
  • WEB_API
  • WEB_UI

我的目标是在服务层中实现身份,以便我的WebAPI和MVC站点都可以利用相同的身份机制。

目前,我很不知所措,在过去的一两天内,我已经阅读了许多教程和文章,并最终选择了重新实现IUserStoreand IRoleStore。并且还可以映射中的不同实体OnModelCreatingMethod

我似乎找不到针对我想要做的教程。我的数据库与众不同,只是简单地重新映射列的名称,而且我不想重新实现整个身份存储,因为只有几个冲突的字段。我发现的大多数tut与使用mysql而不是EF有关。我仍然想使用实体框架。

我遇到的问题:

  • 数据库中的当前用户表使用Intpk,而不是GUID
  • 密码字段使用不同的哈希算法。因此,我需要重写Identity如何检查和存储密码。
  • 我的数据库中没有所有必填的“身份用户”字段,但是我能够添加新字段,只是无法更改现有字段。
  • 由于数据库已经存在,因此我正在使用数据库优先。

所以基本上我的问题是,为了克服上述问题,我需要朝哪个方向前进。我可以放弃更改数据库映射吗?还是我需要重新实现用户和角色存储?

我最初计划的是使用实体框架重新实现用户和角色存储,然后我可以利用数据库的第一个模型类并将实际的数据库结构和字段映射到我的ApplicationUser字段。但是,这是我以为我可能会潜入冷水的地方,如果没有必要,我通常不喜欢重新发明轮子。

c# asp.net asp.net-mvc entity-framework asp.net-identity-2

5
推荐指数
1
解决办法
2543
查看次数

使用JSON在两个C#程序之间传递异常

我有一个Web API,它向执行某些任务/命令的Windows服务发出HTTP请求.

如果我的'service'抛出异常,那么我想使用JSON将该异常传递回Web API.然后我想将异常反序列化回异常对象并抛出它.

我的代码:

Web API和服务之间的共享异常:

public class ConnectionErrorException : Exception
{
    public ConnectionErrorException()
    {
    }
    public ConnectionErrorException(String message)
        : base(message)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

现在在我的服务中,我有以下代码:

       ... 
       try
        {
            result = await ExecuteCommand(userId);
            //If reached here nothing went wrong, so can return an OK result
            await p.WriteSuccessAsync();
        }
        catch (Exception e)
        {
            //Some thing went wrong. Return the error so they know what the issue is
            result = e;
            p.WriteFailure();
        }
        //Write the body of the response:

        //If the result …
Run Code Online (Sandbox Code Playgroud)

c# json exception json.net asp.net-web-api

5
推荐指数
1
解决办法
2529
查看次数