小编Use*_*987的帖子

Visual Studio未知错误的扩展 - 无法推送或获取任何内容

当我尝试通过Visual Studio的Git扩展将任何内容推送到我的bitbucket存储库时出错:

Error encountered while pushing branch to the remote repository: Git failed with a fatal error.
HttpRequestException encountered.
   An error occurred while sending the request.
cannot spawn /C/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/Git/mingw32/libexec/git-core/git-askpass.exe: No such file or directory
could not read Password for ......
Run Code Online (Sandbox Code Playgroud)

这可能是什么问题?

git push bitbucket visual-studio-extensions bitbucket-server

13
推荐指数
2
解决办法
2409
查看次数

SQL Server Web与标准版

我发现有两个版本的SQL Server类型在定价方面有很大差异......

来自我的主机提供商的Web版本每2个核心包大约需要13美元,而标准版大约需要200美元.

从我的角度来看,我们希望我们的数据库大小约为150-200GB,只有少数几个表将占用大部分空间.

所以我唯一担心的是,SQL Server的Web版本是否支持这个大型数据库并且不会给最终用户带来任何性能问题?

Web和Standard版本的索引重建有何不同?

有人可以帮我解决这个问题吗?

sql sql-server performance sql-server-2008 database-indexes

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

使用.NET MVC 5实现基于角色的授权

我想在我正在构建的Web应用程序中实现基于角色的授权.我想象的方法是在我的DB中创建3个表,如下所示:

1. Roles
2. UserRoles (many to many table)
3. Users 
Run Code Online (Sandbox Code Playgroud)

之后,每个用户都将分配一个角色.现在......我的问题是,如何允许或禁止访问.NET MVC应用程序中的特定视图/控制器.我偶然发现了这个:

[Authorize(Roles = "HrAdmin, CanEnterPayroll")]
[HttpPost]
public ActionResult EnterPayroll(string id)
{
    //  . . . Enter some payroll . . . 
}
Run Code Online (Sandbox Code Playgroud)

Authorize属性似乎将特定控制器/操作限制为特定角色......但是,如果我从UserRoles表中读取用户角色,就像我的情况一样?我的应用程序将如何知道用户在系统中扮演什么角色?

有人可以帮我解决这个问题吗?

c# asp.net asp.net-mvc roles asp.net-mvc-4

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

AuthenticationManager类中不存在AuthenticationManager.SignIn()

我正在尝试使用AuthenticationManager该类中的方法SignIn();

我是这样做的:

AuthenticationManager.SignIn(identity);
Run Code Online (Sandbox Code Playgroud)

但它说那里SignIn不存在......

通往的路径AuthenticationManager是:

System.Net.AuthenticationManager
Run Code Online (Sandbox Code Playgroud)

我在这里遗漏了什么吗???

编辑:这是控制器的迷你版本:

using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
using System;
using System.Linq;
using System.Security.Claims;
using System.Web.Mvc;
using WebApplication2.Models;
using WebApplication2.ViewModels;

[HttpPost]
[ActionName("Login")]
public ActionResult Login(LoginViewModel model)
{
    if (ModelState.IsValid)
    {
        string userName = (string)Session["UserName"];
        string[] userRoles = (string[])Session["UserRoles"];

        ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);

        identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName));

        userRoles.ToList().ForEach((role) => identity.AddClaim(new Claim(ClaimTypes.Role, role)));

        identity.AddClaim(new Claim(ClaimTypes.Name, userName));

        AuthenticationManager.SignIn(identity);
        return RedirectToAction("Success");
    }
    else
    {
        return View("Login",model);
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:出现新错误:

The following errors …
Run Code Online (Sandbox Code Playgroud)

c# asp.net authentication asp.net-mvc

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

当前上下文中不存在名称"DefaultAuthenticationTypes"

我正在尝试在我的Web应用程序中实现基于角色的授权,如下所示:

[HttpPost]
[ActionName("Login")]
public ActionResult Login(LoginViewModel model)
{
    if (ModelState.IsValid)
    {
        string userName = model.Username;
        string[] userRoles = (string[])Session["UserRoles"];

        ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);

        identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName));

        userRoles.ToList().ForEach((role) => identity.AddClaim(new Claim(ClaimTypes.Role, role)));

        identity.AddClaim(new Claim(ClaimTypes.Name, userName));

        AuthenticationManager.SignIn(identity);

        return RedirectToAction("Success");
    }
    else
    {
        return View("Login",model);
    }
}
Run Code Online (Sandbox Code Playgroud)

我在两行上出错了:

1.ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
Run Code Online (Sandbox Code Playgroud)

和:

2.AuthenticationManager.SignIn(identity);
Run Code Online (Sandbox Code Playgroud)

错误1:

the name 'DefaultAuthenticationTypes' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)

错误2是:

Authentication manager does not contains definition for SignIn
Run Code Online (Sandbox Code Playgroud)

我试图找到一个解决方案如何实现这个,但我找不到任何与错误相关的内容.

c# asp.net asp.net-mvc applicationmanager asp.net-mvc-5

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

正则表达式只从字符串中删除特定的特殊字符

我想写一个正则表达式,将删除以下基础上的特殊字符:

  • 删除空格字符
  • @,&,',(,), <, >#

我写了这个正则表达式成功删除空格:

 string username = Regex.Replace(_username, @"\s+", "");
Run Code Online (Sandbox Code Playgroud)

但我想升级/更改它,以便它可以删除我提到的上面的字符.

有人可以帮我解决这个问题吗?

c# regex asp.net special-characters c#-4.0

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

C#使用SQLBulkCopy或等效库高效批量删除50000条记录

我正在使用这个库来批量执行批量删除,如下所示:

  while (castedEndedItems.Any())
  {
    var subList = castedEndedItems.Take(4000).ToList();
    DBRetry.Do(() => EFBatchOperation.For(ctx, ctx.SearchedUserItems).Where(r => subList.Any(a => a == r.ItemID)).Delete(), TimeSpan.FromSeconds(2));
    castedEndedItems.RemoveRange(0, subList.Count);
    Console.WriteLine("Completed a batch of ended items");
  }
Run Code Online (Sandbox Code Playgroud)

如您所见,我一次删除了一批 4000 个项目,并将它们作为参数传递给查询...

我正在使用这个库来执行批量删除:

https://github.com/MikaelEliasson/EntityFramework.Utilities
Run Code Online (Sandbox Code Playgroud)

然而,这样的性能绝对是糟糕的......我测试了几次应用程序并删除了 80000 条记录,例如需要 40 分钟!?

我应该注意,我要删除的参数 (ItemID) 是 varchar(400) 类型,并且出于性能原因对其进行了索引....

是否有任何其他库可以使用或调整此查询以使其工作得更快,因为目前的性能绝对糟糕..:/

c# asp.net asp.net-mvc bulk bulk-delete

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

在 .NET C# 中使用 httpclient 并发执行 http 请求

我制作了一个控制台应用程序,它基本上对我的服务器执行大量请求。每个用户 10-15000 个请求。

所以我编写了使用 .NET 的 HTTP 客户端库的代码:

public async Task<string> DoRequest(string token)
{

var request = new HttpRequestMessage(HttpMethod.Post, "mysite.com");
string requestXML = "my xml request goes her...";
request.Content = new StringContent(requestXML, Encoding.UTF8, "text/xml");
var response = await httpClient.SendAsync(request);
return await response.Content.ReadAsStringAsync();
}
Run Code Online (Sandbox Code Playgroud)

所以现在我尝试每 1 秒执行尽可能多的 HTTP 请求...我不知道这个上限是多少,所以我使用并行 for 循环来加速:

Parallel.For(0,list.Count(),items=>{
DoRequest(item.Token);
});
Run Code Online (Sandbox Code Playgroud)

但我对代码的速度以及请求的发出方式不太满意......

有什么方法可以加快速度,每 1 秒最多可以处理 10-100 个请求?或者最大限制是多少?

有人可以帮我吗 ?

PS,我只创建了一个 httpclient 类的实例,因为我读到,只创建一个实例是一种很好的做法,因为每次创建该类的新对象时,连接都会关闭,这不是我们想要的不是吗?

c# asp.net request console-application dotnet-httpclient

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

C#/.NET 比较两个大列表并从两个列表中查找丢失的项目

所以基本上我有两个大列表,如下所示:

public class Items
{
 public string ItemID { get; set; }
}


var oldList = new List<Items>(); // oldList

var newList = new List<Items>(); // new list
Run Code Online (Sandbox Code Playgroud)

两个列表都非常大,如果它们都很大(超过 30 秒),由于执行时间很短,简单的双 foreach 将是不够的。

在我在 stackoverflow 上问过的上一个问题中,我得到了关于如何比较这两个相同列表并找出哪些项目具有不同 QuantitySold 参数的回复,然后将其存储在名为“DifferentQuantityItems”的第三个列表中,如下所示:

var differentQuantityItems =
    (from newItem in newList
     join oldItem in oldList on newItem.ItemID equals oldItem.ItemID
     where newItem.QuantitySold != oldItem.QuantitySold
     select newItem).ToList();
Run Code Online (Sandbox Code Playgroud)

现在我想从这两个列表中得到以下内容:

- A list of items that are present in newList, but not in oldList

- A list of items that …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

使用jQuery/JavaScript复制到剪贴板文本框值

我有一个文本框和按钮,如下所示:

     <div class="col-xs-11" style="padding:20px 0 ">
     <input type="text" class="form-control txtKeywords" id="txtKeyw" style="margin-bottom:10px; height:45px;" maxlength="80" placeholder="Click on keywords to combine your title">
   <button type="submit" class="btn btn-space btn-success btn-shade4 btn-lg copyToClipboard">
    <i class="icon icon-left s7-mouse"></i> Copy to Clipboard
     /button>
Run Code Online (Sandbox Code Playgroud)

当用户点击按钮复制到剪贴板时,我想将文本框的内容复制到剪贴板中,如下所示:

$(document).on("click", ".copyToClipboard", function () {
    copyToClipboard("txtKeyw");
    successMessage();
});
Run Code Online (Sandbox Code Playgroud)

其中copyToClipboard函数的定义是:

 function copyToClipboard(element) {
            var $temp = $("<input>");
            $("body").append($temp);
            $temp.val($(element).text()).select();
            document.execCommand("copy");
            $temp.remove();
        }
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,没有任何反应 - 没有值从文本框复制到剪贴板......我在这里做错了什么?

更多信息:

  • 这种情况发生在Chrome 59 64位和Firefox 54 32位中.
  • successMessage() 被调用并显示在浏览器中.
  • #在元素ID之前添加不能解决问题.

javascript clipboard jquery copy input

4
推荐指数
1
解决办法
9409
查看次数