小编Kar*_*mar的帖子

HttpClient - 任务被取消了?

当有一个或两个任务时它可以正常工作但是当我们列出了多个任务时会抛出错误"任务被取消".

在此输入图像描述

List<Task> allTasks = new List<Task>();
allTasks.Add(....);
allTasks.Add(....);
Task.WaitAll(allTasks.ToArray(), configuration.CancellationToken);


private static Task<T> HttpClientSendAsync<T>(string url, object data, HttpMethod method, string contentType, CancellationToken token)
{
    HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, url);
    HttpClient httpClient = new HttpClient();
    httpClient.Timeout = new TimeSpan(Constants.TimeOut);

    if (data != null)
    {
        byte[] byteArray = Encoding.ASCII.GetBytes(Helper.ToJSON(data));
        MemoryStream memoryStream = new MemoryStream(byteArray);
        httpRequestMessage.Content = new StringContent(new StreamReader(memoryStream).ReadToEnd(), Encoding.UTF8, contentType);
    }

    return httpClient.SendAsync(httpRequestMessage).ContinueWith(task =>
    {
        var response = task.Result;
        return response.Content.ReadAsStringAsync().ContinueWith(stringTask =>
        {
            var json = stringTask.Result;
            return Helper.FromJSON<T>(json);
        }); …
Run Code Online (Sandbox Code Playgroud)

c# task-parallel-library dotnet-httpclient

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

Spring Batch 死锁 - 无法增加身份;嵌套异常是 com.microsoft.sqlserver.jdbc.SQLServerException

我们正在将 Spring Batch 应用程序从 Oracle DB 迁移到 Azure SQL Server。

我在尝试同时执行两个不同的作业来更新不同的表时收到以下错误,但使用相同的通用 BATCH_ 表

导致:org.springframework.dao.DataAccessResourceFailureException:无法增加身份;嵌套异常是 com.microsoft.sqlserver.jdbc.SQLServerException:事务(进程 ID 167)在锁资源上与另一个进程发生死锁,并已被选为死锁受害者。重新运行事务。在 org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer.getNextKey(SqlServerMaxValueIncrementer.java:124) ~[bat-applybatch-jobs-2.2.12-SNAPSHOT.jar:?] 在 org.springframework.jdbc.support.incrementer。 AbstractDataFieldMaxValueIncrementer.nextLongValue(AbstractDataFieldMaxValueIncrementer.java:125)

我的作业存储库配置

<job-repository id="jobRepository" isolation-level-for-create="READ_COMMITED" />
Run Code Online (Sandbox Code Playgroud)

数据库死锁

<deadlock>
  <victim-list>
    <victimProcess id="process2a41675a4e8" />
  </victim-list>
  <process-list>
    <process id="process2a41675a4e8" taskpriority="0" logused="280" waitresource="RID: 6:9:24682488:29" waittime="4984" ownerId="696000712" transactionname="implicit_transaction" lasttranstarted="2021-12-29T12:18:30.153" XDES="0x29a22bc4428" lockMode="U" schedulerid="4" kpid="52760" status="suspended" spid="173" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2021-12-29T12:18:30.157" lastbatchcompleted="2021-12-29T12:18:30.153" lastattention="1900-01-01T00:00:00.153" clientapp="Microsoft JDBC Driver for SQL Server" hostname="ServerName" hostpid="0" loginname="LoginName" isolationlevel="read committed (2)" xactid="696000712" currentdb="6" currentdbname="Database" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
      <executionStack>
        <frame …
Run Code Online (Sandbox Code Playgroud)

java sql-server spring spring-batch azure-sql-server

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

如何使用声明身份验证保护SharePoint 2013中的应用程序页面

我想使用声明身份验证来保护SharePoint 2013中的应用程序页面,但它似乎不起作用.

<configuration>
   <location path="_layouts/15/settings">
      <system.web>
         <authorization>
            <allow users="demo\user1"/>
            <deny users="*" />
         </authorization>
      </system.web>
   </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但它适用于基于Windows的身份验证.

更新:5月21日至15日:

我修好了

<configuration>
   <location path="_layouts/15/settings">
      <system.web>
         <authorization>
            <allow users="0#.w|demo\user1"/>
            <deny users="*" />
         </authorization>
      </system.web>
   </location>
Run Code Online (Sandbox Code Playgroud)

但它没有授权AD组,尝试过如下所述.

<allow users="c:0+.w|demo\group1"/>
<allow roles="c:0+.w|demo\group1"/>
<allow users="0+.w|demo\group1"/>
<allow roles="0+.w|demo\group1"/>
<allow users="demo\group1"/>
<allow roles="demo\group1"/>
<allow users="c:0+.w|sid"/>
<allow roles="c:0+.w|sid"/>
<allow users="0+.w|sid"/>
<allow roles="0+.w|sid"/>
<allow users="sid"/>
<allow roles="sid"/>
Run Code Online (Sandbox Code Playgroud)

如何授权个人用户和AD组?

更新:2015年5月22日

  <location path="_layouts/15/viewlsts.aspx">
    <system.web>
      <authorization>
        <allow users="Group1" />
        <allow users="Domain\Group1" />
        <allow users="0#.w|Domain\Group1" />
        <allow users="c:0+.w|Domain\Group1" />
        <allow users="s-1-5-21-1971354296-1767978563-xxxxxxx-yyyyyy" />
        <allow users="0+.w|s-1-5-21-1971354296-1767978563-xxxxxxx-yyyyyy" …
Run Code Online (Sandbox Code Playgroud)

sharepoint authorization iis-7.5

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

Windows工作流基础中基于人的任务

我试图在Windows工作流基础4.5中构建一个简单的请假申请,它会在工作流尝试完成而不等待approveRequest活动时抛出以下异常.

具有相同ServiceContractName和OperationName'ApplyLeave'的两个SendParameters对象具有不同的参数名称.

你能告诉我缺少什么吗?

using System;
using System.ServiceModel.Activities;
using System.Activities;
using System.ServiceModel;
using System.Activities.Statements;

namespace DemoWF
{
    public class _25_LeaveRequest
    {
        public WorkflowService GetInstance()
        {
            WorkflowService service;
            Variable<int> empID = new Variable<int> { Name = "empID" };
            Variable<int> requestID = new Variable<int> { Name = "requestID" };

        Receive receiveLeaveRequest = new Receive
        {
            ServiceContractName = "ILeaveRequestService",
            OperationName = "ApplyLeave",
            CanCreateInstance = true,
            Content = new ReceiveParametersContent
            {
                Parameters ={
                    {"empID",new OutArgument<int>(empID)}
                }
            }
        };

        SendReply replyLeaveRequestID = new SendReply
        {
            Request …
Run Code Online (Sandbox Code Playgroud)

c# workflow-foundation workflow-foundation-4

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

ASP.Net ListView按数据字段分组?

我使用asp.net listview控件来显示细节.每个项目都有组详细信息.出于演示目的,组是硬编码的.

我想显示listview,如下所示

在此输入图像描述

现在,我有这个

在此输入图像描述

码:

    <asp:ListView ID="HyperLinkListView" runat="server" ViewStateMode="Disabled" ItemPlaceholderID="itemContainer" GroupPlaceholderID="groupContainer">
    <LayoutTemplate>
        <section class="quick-links">
            <div class="row">
                <div class="dfwp-column" style="width: 100%">
                    <div class="slm-layout-main groupmarker">
                        <ul class="dfwp-list">
                            <asp:PlaceHolder ID="groupContainer" runat="server" />
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </LayoutTemplate>
    <GroupTemplate>
        <span>Group</span>
        <asp:PlaceHolder ID="itemContainer" runat="server" />
    </GroupTemplate>
    <ItemTemplate>
        <li>
            <div class="item">
                <div class="link-item">
                    <asp:HyperLink Target="_blank" ID="hyperlink" NavigateUrl='<%# this.LinkToPlay((((SPListItem)Container.DataItem)["VideoFileName"]).ToString()) %>' Text='<%# Eval("Title") %>' runat="server" />
                    </a>
                </div>
            </div>
        </li>
    </ItemTemplate>
    <EmptyDataTemplate>
        <span>No data was returned.</span>
    </EmptyDataTemplate>
</asp:ListView>
Run Code Online (Sandbox Code Playgroud)

我该如何实现这一目标?

asp.net listview asp.net-controls

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

从远程文件共享下载文件会导致拒绝访问

我在ASP.Net Generic处理程序中有以下代码来下载文件.

// generate you file
// set FilePath and FileName variables
string stFile = FilePath + FileName;
try {
    response.Clear();
    response.ContentType = "application/pdf";
    response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
    response.TransmitFile(stFile);
} catch (Exception ex) {
    // any error handling mechanism
} finally {
    response.End();
}
Run Code Online (Sandbox Code Playgroud)

它适用于本地路径 - 如"D:\ Files\Sample.pdf"或"\ localserver\Files\Sample.pdf".

但它在尝试访问网络文件共享时抛出并访问被拒绝的错误,如"\ anotherServer\Files\Sample.pdf".

它与双跳有关吗?如果我可以使用spsecurity.runwithelevatedprivileges来解决此问题?或者其他选择是什么?

根据这篇文章,https://weblogs.asp.net/owscott/iis-windows-authentication-and-the-double-hop-issue似乎是一个双跳问题.我该如何解决这个问题?我想要的是最终用户应该能够使用asp.net泛型处理程序下载远程资源.

c# asp.net sharepoint httpresponse ashx

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

Azure 应用程序网关 - 有什么理由让 Azure 防火墙落后?

我在 Azure API 管理前面有 Azure 应用程序网关,并且可以看到,在 Internet 上的大多数可用方案中,Azure 应用程序网关和 Azure API 管理之间都有防火墙。

由于 Azure 应用程序网关本身就是一个防火墙,是否有任何理由将 Azure 防火墙置于其后面。

firewall azure azure-application-gateway

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

Spring Batch:无法增加身份;嵌套异常是 com.microsoft.sqlserver.jdbc.SQLServerException:对象名称“BATCH_JOB_SEQ”无效?

我们正在将 Spring Batch 应用程序从 Oracle DB 迁移到 Azure SQL Server。

我在尝试执行迁移到 SQL Server 后的作业时收到以下错误

无法增加身份;嵌套异常是 com.microsoft.sqlserver.jdbc.SQLServerException:无效的对象名称“AppName.BATCH_JOB_SEQ”。

我可以确定 SQL Server 具有所需的序列

在此输入图像描述

在作业存储库配置下方

<batch:job-repository id="jobRepository"
 isolation-level-for-create="READ_COMMITTED"
 table-prefix="MyApp.BATCH_"/>
Run Code Online (Sandbox Code Playgroud)

以下是 Oracle 中可用的表和序列

在此输入图像描述 在此输入图像描述

下面是 Azure SQL 中可用的表和序列

在此输入图像描述 在此输入图像描述

我正在使用以下版本 在此输入图像描述

我应该升级到

在此输入图像描述

或者我应该按照https://github.com/spring-projects/spring-batch/blob/main/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-重新创建表sqlserver.sql

java sql-server oracle spring spring-batch

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

如何在 ASP.Net Core 6.0 中实现 HSTS 标头?

我需要在 ASP.Net Core 6.0 WEB API 应用程序中实现 HSTS 标头安全性。

下面是我的Program.cs

    var builder = WebApplication.CreateBuilder(args);
    ...
    // Https redirection
    builder.Services.AddHttpsRedirection(options =>
    {
        options.RedirectStatusCode = (int)HttpStatusCode.TemporaryRedirect;
        options.HttpsPort = 7075;
    });
    
    // HSTS Security Headers 
    builder.Services.AddHsts(options =>
    {
        options.Preload = true;
        options.IncludeSubDomains = true;
        options.MaxAge = TimeSpan.FromDays(365);
    });
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    if (app.Environment.IsDevelopment())
    {
        app.UseSwagger();
        app.UseSwaggerUI();
        app.UseHsts();
    }
    
    app.UseHttpsRedirection();
    
    app.UseAuthorization();
    
    app.UseCustomExceptionHandler();
    
    app.MapControllers();
    
    app.Run();
Run Code Online (Sandbox Code Playgroud)

下面是launchSettings.json

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": …
Run Code Online (Sandbox Code Playgroud)

c# asp.net hsts asp.net-core asp.net-core-6.0

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

完成请求后,如何处置由Unity DI创建的对象?

我想知道是否有更好的方法来处理此问题。

我已经为我们的项目设置了Unity以进行依赖项注入。该项目本身是使用Web API的ASP.NET应用程序。

我安装了以下软件包。

  • 统一
  • Unity.ASPNet.WebAPI

我看不到在获取数据后立即关闭/处置DBContext的选项。

我的控制器

public class NinjasController : ApiController
{
    public Ninja Get(int id)
    {
        INinjaRepository repository = UnityConfig.Container.Resolve(typeof(INinjaRepository), null) as INinjaRepository;
        Ninja ninja = repository.GetNinjaById(id);
        repository.CanBeDisposed = true;
        repository = null;
        UnityConfig.PerRequestLifetimeManager.Dispose();
        return ninja;
    }
}
Run Code Online (Sandbox Code Playgroud)

UnityConfig

public static class UnityConfig
{
    private static Lazy<IUnityContainer> container =
      new Lazy<IUnityContainer>(() =>
      {
          var container = new UnityContainer();
          RegisterTypes(container);
          return container;
      });

    public static IUnityContainer Container => container.Value;
    public static PerRequestLifetimeManager PerRequestLifetimeManager;

    public static void RegisterTypes(IUnityContainer container) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net entity-framework unity-container asp.net-web-api

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