我有一个字符串数组
var ids = new string[]
{
"1408576188",
"1750854738",
"100001058197465"
};
Run Code Online (Sandbox Code Playgroud)
我想将这个字符串数组作为json数组传递给API.目前,API 无法接受从以下位置返回的字符串:
JsonConvert.SerializeObject(ids);
Run Code Online (Sandbox Code Playgroud)
所以我发现我能够通过将我的ids数组转换为JArray对象来使用API .
JArray.Parse(JsonConvert.SerializeObject(ids));
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我在这里做了两个操作,首先我序列化ids数组,然后我将结果解析成JArray.有没有办法将我的ids数组直接转换为JArray对象?
例1:
if ((Value ?? 0d) <= 0d)
{
//some code
}
Run Code Online (Sandbox Code Playgroud)
例2:
if ((Value ?? (double)0) <= (double)0)
{
//some code
}
Run Code Online (Sandbox Code Playgroud)
这两者有什么区别?哪一个更好用?
当用户在浏览器中单击后退或前进按钮时,我想取消路由更改.到目前为止,我设法捕获路由更改事件,如下面的代码:
constructor(router:Router) {
router.events
.subscribe((event:Event) => {
// some logic.
// event.preventDefault(); ?
});
}
Run Code Online (Sandbox Code Playgroud)
我在事件中找不到任何方法/成员来停止事件默认.然后我会在控制台上收到此错误,因为我没有按预期注册路由配置,这是因为我location.go()用来修改网址.
错误:未捕获(在承诺中):错误:无法匹配任何路由:'Some/Url'
有没有办法取消路由更改,以便Angular不查看路由配置?
我正在尝试编写一个PowerShell脚本,该脚本允许用户授权Azure Active Directory应用程序代表他们执行操作。
遵循Microsoft的“授权代码授予”流程文档。我通过以下行调用Authorization端点:
Invoke-WebRequest -Method GET -Uri "https://login.microsoftonline.com/$tenantId/oauth2/authorize?client_id=$applicationId&response_type=code&redirect_uri=$redirectUri&response_mode=query&resource=$resource&state=09876"
Run Code Online (Sandbox Code Playgroud)
它同时在PowerShell中返回响应,并同时在默认浏览器中打开网页。
以下是响应的样子:
StatusCode : 200
StatusDescription : OK
Content :
<!DOCTYPE html>
<html dir="ltr" class="" lang="en">
<head>
<title>Sign in to your account</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-eq...
RawContent : HTTP/1.1 200 OK
Pragma: no-cache
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
x-ms-request-id: ed3ee9de-ccc4-47ea-ac52-087b...
Forms : {}
Headers : {[Pragma, no-cache], [Strict-Transport-Security, max-age=31536000; includeSubDomains],
[X-Content-Type-Options, nosniff], [X-Frame-Options, DENY]...}
Images : {}
InputFields : {}
Links : {} …Run Code Online (Sandbox Code Playgroud) 我按照本指南设置自己的NuGet私有服务器,但使用的是Visual Studio 2010.
我已经成功添加了NuGet.Server包Package Manager Console,但是当我想构建WebApplication时,我遇到了错误:
名称空间'NuGet'中不存在类型或命名空间名称'Server'(您是否缺少程序集引用?)
软件包安装中没有错误,但是我发现NuGet.Server项目的参考文件夹中没有添加错误,为什么会这样?
编辑:进一步调查包内容,我看到NuGet.Server没有libfor net40.我可能需要派生NuGet.Server源并编译它net40来解决这个问题.
这是我的日志来自Package Manager Console:
PM> Install-package nuget.server
Attempting to resolve dependency 'NuGet.Core (? 2.10.1)'.
Attempting to resolve dependency 'Microsoft.Web.Xdt (? 2.1.0)'.
Attempting to resolve dependency 'Newtonsoft.Json (? 8.0.1)'.
Attempting to resolve dependency 'RouteMagic (? 1.3.0)'.
Attempting to resolve dependency 'WebActivatorEx (? 2.1.0)'.
Attempting to resolve dependency 'Microsoft.Web.Infrastructure (? 1.0.0.0)'.
Installing …Run Code Online (Sandbox Code Playgroud) 我正在使用身份服务器4的web api.我不知道从哪里开始编写集成测试.我有一个登录控制器接收用户名和密码,用于ResourceOwnerPassword授权类型.以下是我的代码.
控制器.
[Route("Authentication/Login")]
public async Task<IActionResult> WebApiLogin(string username, string password)
{
var accessToken = await UserAccessToken.GenerateToken(username, password);
return new JsonResult(accessToken);
}
Run Code Online (Sandbox Code Playgroud)
用于生成令牌的类
public async Task<string> GenerateToken(string username, string password)
{
//discover endpoint for metadata
var disco = await DiscoveryClient.GetAsync("http://localhost:5000");
//request token
var clientToken = new TokenClient(disco.TokenEndpoint, "client", "secret");
//var tokenResponse = await clientToken.RequestClientCredentialsAsync("Payment");
var tokenResponse = await clientToken.RequestResourceOwnerPasswordAsync(username, password, "IntegrapayAPI");
if (tokenResponse.IsError)
{
//Error tokenResponse.Error
return tokenResponse.Error;
}
return tokenResponse.Json.ToString();
}
Run Code Online (Sandbox Code Playgroud)
IdentityServer Project启动类.
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer() …Run Code Online (Sandbox Code Playgroud) 我写了这段代码,它工作正常。有没有更好的方法LINQ可以减少时间复杂度。
List<int> list = new List<int>() { 1, 2, 3, 1, 2, 3, 1, 2, 7, 2, 2 };
var distinctList = list.Distinct();
var listWithCount = distinctList.Select(q=>new { num=q, count = list.Count(number=>number==q) });
foreach(var number in listWithCount)
{
Console.WriteLine("num : " + number.num + " count : " + number.count);
}
Run Code Online (Sandbox Code Playgroud) 我有一个 Windows 应用程序,用户在其中输入开始时间和结束时间,如何检查结束时间是否是第二天的时间。
example: start time end time
1:00:00 AM 5:00:00 AM
5:00:00 AM 10:00:00 AM
10:00:00 AM 5:00:00 PM
5:00:00 PM 10:00:00 PM
10:00:00 PM 1:00:00 AM --(next day)
1:00:00 AM 5:00:00 AM
Run Code Online (Sandbox Code Playgroud)
我正在尝试如下所示:
private void GenerateReportWithStartTimeandEndTime(string StartTime, string EndTime, string DailyTime)
{
DateTime tempStartTime = DateTime.ParseExact(StartTime, "HH:mm:ss tt", CultureInfo.InvariantCulture);
DateTime tempEndTime = DateTime.ParseExact(EndTime, "HH:mm:ss tt", CultureInfo.InvariantCulture);
DateTime midNightToday = DateTime.Today.AddDays(1);
var StarthourDifference = (midNightToday - tempStartTime).TotalHours;
var EndhourDifference = (midNightToday - tempEndTime).TotalHours;
if (StarthourDifference - EndhourDifference > 0) …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×1
angular ×1
asp.net-core ×1
asp.net-mvc ×1
azure ×1
count ×1
javascript ×1
json.net ×1
linq ×1
list ×1
nuget ×1
nuget-server ×1
oauth-2.0 ×1
powershell ×1