小编Fir*_*ion的帖子

Web API Gzip未被应用

我添加了web.config条目以启用基于此S/O答案启用IIS7 gzip的 gzip压缩.

然后我在加载ASPX页面时检查了Chrome Developer窗口,并在响应中看到了标题:

Cache-Control:private
Content-Encoding:gzip
Content-Length:3669
Content-Type:text/html; charset=utf-8
Date:Wed, 04 Mar 2015 00:46:05 GMT
Server:Microsoft-IIS/7.5
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Run Code Online (Sandbox Code Playgroud)

这意味着它"正常",对吗?但是在进行Web API调用时查找该标头时,它不存在:

Cache-Control:no-cache
Content-Length:551
Content-Type:application/json; charset=utf-8
Date:Wed, 04 Mar 2015 00:53:05 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Run Code Online (Sandbox Code Playgroud)

我尝试了各种不同的配置(从上面链接的S/O答案中推荐的配置开始).最后,在绝望的行为中,我将其设置为此,我认为它会尝试压缩所有请求(除了*/*注释掉的所有内容):

  <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
    <dynamicTypes>
      <add mimeType="*/*" enabled="true"/>
      <!--<add mimeType="text/*" enabled="true"/>
      <add mimeType="message/*" enabled="true"/>
      <add mimeType="application/javascript" enabled="true"/>
      <add mimeType="application/json" enabled="true"/>-->
      <!--<add mimeType="*/*" enabled="false"/> -->
    </dynamicTypes>
    <staticTypes>
      <add mimeType="*/*" enabled="true"/>
      <!--<add mimeType="text/*" enabled="true"/>
      <add …
Run Code Online (Sandbox Code Playgroud)

c# gzip asp.net-web-api2

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

Entity Framework Core 3 原始 SQL 缺少方法

我正在尝试使用 EF Core 3 从表中删除所有行,例如:

db.MyTable.ExecuteSqlRaw("delete from MyTable;");
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

DbSet' 不包含 'ExecuteSqlRaw' 的定义,并且找不到接受类型为 'DbSet' 的第一个参数的可访问扩展方法 'ExecuteSqlRaw'(您是否缺少 using 指令或程序集引用?)

EF Core 3 的 Microsoft 重大更改页面没有提供关于是否需要特殊包来启用此功能的任何建议:

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/break-changes#fromsql-executesql-and-executesqlasync-have-been-renamed

这些是我安装的 Nuget 包:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Expressions" Version="4.3.0" />
<PackageReference Include="System.Linq.Queryable" Version="4.3.0" />
Run Code Online (Sandbox Code Playgroud)

使用语句:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
Run Code Online (Sandbox Code Playgroud)

请注意,FromSqlRaw是可用的,但是ExecuteSqlRawExecuteSqlRawAsync等等都没有。

编辑:我添加了一个using Microsoft.EntityFrameworkCore,错误已更改为:

“DbSet”不包含“ExecuteSqlRaw”的定义,并且最佳扩展方法重载“RelationalDatabaseFacadeExtensions.ExecuteSqlRaw(DatabaseFacade, string, params object[])”需要“DatabaseFacade”类型的接收器

c# entity-framework entity-framework-core .net-core ef-core-3.0

8
推荐指数
3
解决办法
5308
查看次数

.Net Core 3 Blazor Server - 如何使用声明进行基本登录?

我已经有包含用户名、密码和角色 ID 的表,所以我不想使用 ASP.NET Membership 表。而且我只需要一个要求输入用户名和密码的简单登录页面,而不是他们预先构建的 Identity.UI 包。

但我不知道如何让 Blazor Server 为我进行基本登录。我有我认为应该在 Startup.cs 中配置的基础知识,例如:

在配置服务中:

services
    .AddAuthentication(Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie();
Run Code Online (Sandbox Code Playgroud)

在配置()中:

app.UseAuthentication();
app.UseAuthorization();
Run Code Online (Sandbox Code Playgroud)

通常我会这样称呼:

await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, 
    principal, 
    new AuthenticationProperties { IsPersistent = loginData.RememberMe });
Run Code Online (Sandbox Code Playgroud)

事实上,如果我从 .cshtml 页面运行它,上面的确实有效,但我希望它作为 Blazor 组件 (.razor) 工作。

我尝试注入httpContextAccessor但尝试SignInAsync从那里调用该方法导致有关已设置标头的错误。

我有一个 .razor 登录组件,我不知道该调用什么来进行实际登录。

@page "/login"


@using Microsoft.AspNetCore.Authentication.Cookies;
@using Microsoft.AspNetCore.Components;
@using System.Security.Claims;


@inject NavigationManager navigationManager
@inject DataAccess.Models.CurrentDataContext db

<h3>Login</h3>

<div>
    Email:
    <input type="text" @bind="@email" />
</div>

<div>
    Password:
    <input type="text" @bind="@password" />
</div>

<div>
    <button …
Run Code Online (Sandbox Code Playgroud)

c# .net-core blazor

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

NetSuite API:更新自定义对象字段

我正在尝试更新自定义对象中的字段,但是当我这样做时出现错误java.lang.NullPointerException

异常的代码对象中也有这个:http://schemas.xmlsoap.org/soap/envelope/:Server.userException这个 S/O 线程表明我发送的请求可能有问题,导致服务器抛出异常。但是什么?异常中没有详细信息。

据我所知,我正在遵循“SuiteTalk(Web 服务)平台指南”中的更新示例,但这是“CustomRecord”而非“客户”,因此我必须进行一些更改。

这是我必须帮助更新 CustomRecords 的方法。错误发生在我实际发出请求的最后一行:

private static void UpdateCustomRecordValue(CustomRecord customRecord, string fieldName, string newValue, NetSuiteService netsuiteService)
{
    var field = customRecord.customFieldList.Where(custField => custField.scriptId == fieldName).FirstOrDefault();

    if (field == null) return;

    var updateRecord = new CustomRecord();
    updateRecord.scriptId = customRecord.scriptId;

    CustomFieldRef[] custFieldList = new CustomFieldRef[] {
        new StringCustomFieldRef
        {
            value = newValue, 
            scriptId = field.scriptId
        }
    };

    updateRecord.customFieldList = custFieldList;
    var updateResponse = netsuiteService.update(updateRecord);

}
Run Code Online (Sandbox Code Playgroud)

c# soap netsuite

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

将Kendo DataSourceRequest转换回查询字符串

Kendo MVC库中是否有内置的帮助器,可以将Kendo Grid的DataSourceRequest对象从MVC6控制器内部转换回查询字符串?像是“模型解开器”?

如果DataSourceRequest是一个简单的对象,则可以更轻松地滚动自己的对象,但是由于它具有更复杂的结构,因此我希望已经有了“ Kendo方式”。我还可以从中获取整个查询字符串,Request.QueryString.Value但希望在有更多参数的情况下,我可以轻松地仅隔离数据源部分。

像这样:

public int GetStuff([DataSourceRequest]DataSourceRequest request)
{
    var res = 0;
    try
    {
        //something like these which do not really exist?
        var kendoQS1 = request.ToQueryString(); 
        var kendoQS2 = KendoDataSourceQueryStringBuilder.FromDataSource(request);

       //do stuff with kendoQS
    }
    catch (Exception ex)
    {
        //...
    }
    return res ;
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc kendo-ui kendo-asp.net-mvc

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

.NET Core 3 MVC 从 HTTP 下载文件并使用最小内存重新传递给客户端

我有一个 .NET Core 3 MVC 应用程序,需要通过 HTTP 从一个位置读取文件,然后将其重新传递回响应。其中一些文件的大小约为 200MB。

File我所拥有的有效,但它在将结果发送给客户端之前将整个文件读取到内存中。有没有一种方法可以使其本质上成为一个直通,其中读取流流入响应流,以便服务器上需要很少的内存?

这是我现在所拥有的,但我认为对于大文件来说效果不佳:

if (requestedFile != null)
{
    using (var client = new System.Net.Http.HttpClient())
    {
        using (var result = await client.GetAsync(requestedFile.DownloadUrl))
        {
            if (result.IsSuccessStatusCode)
            {
                var bytes = await result.Content.ReadAsByteArrayAsync();
                return File(bytes, "application/zip", "largefile.zip");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过这会导致“无法访问关闭的流”的运行时错误:

using (var client = new System.Net.Http.HttpClient())
{
    using (var httpResponseMessage = await client.GetAsync(requestedFile.DownloadUrl))
    {
        return File(await httpResponseMessage.Content.ReadAsStreamAsync(), "application/zip", "largefile.zip");

    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

经过一番尝试和错误后的解决方案是删除所有 using 语句并让其FileStreamResult自行关闭流。所以我最终得到:

var client = new HttpClient(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc .net-core

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

将链接/模板列添加到自定义表组件

我根据本文构建了一个表组件:从头开始创建Angular2数据表

我一直在扩展它,以便做我的应用程序需要的其他事情(例如排序和分页),但是我不知道的一件事是如何提供某种“模板列”以允许创建类似编辑/删除链接。

我试图弄清楚如何开始<ng-content>工作,ColumnComponent以便可以通过这种方式传递链接/ routerlink模板,但是我无法通过构建此表的方式来做到这一点。

这是我的组件的简化版本:

普伦克

现在的(简化)组件:

datatable.component.html

<table class="table table-striped table-hover">
    <thead>
        <tr>
            <th *ngFor="let column of columns">
              {{column.header}}
            </th>
        </tr>
    </thead>
    <tbody *ngFor="let row of dataset; let i = index">
        <tr>
            <td *ngFor="let column of columns">
              {{row[column.value]}}
            </td>
        </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

datatable.component.ts

import { Http, Response } from '@angular/http';
import { Injectable, Component, Input, Output, EventEmitter } from '@angular/core';
import { ColumnComponent } from './column.component';

@Component({
    selector: 'datatable',
    templateUrl: 'src/datatable.component.html'
})
export …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

网络服务或 AppPool 帐户的始终加密证书

我正在尝试将 Always Encrypted 应用程序部署到 Amazon AWS。有一个 2016 RDS 数据库和一个托管 ASP.NET 4.6 应用程序的 Windows Server 2016。

在 Windows Server 上,当应用程序在网络服务或应用程序池标识下运行时,我们得到的正是我非常确定的问题

我们的错误:

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

  • 我们尝试了该帖子中的解决方案,但没有成功
  • 我们尝试了这篇文章中的解决方案,但无法让 powershell 脚本返回除运行时异常之外的任何内容。我对 powershell 不太熟悉,所以也许我不明白这个脚本。
  • 如果我们将证书导入到管理员帐户,并使用管理员帐户运行 IIS 应用程序池,则一切正常(不是连接问题或任何问题)
  • 我们尝试将证书导入本地计算机“个人”证书,并赋予应用程序帐户对密钥的完全控制权
  • 我们尝试将证书导入到本地计算机受信任的根证书颁发机构(如 as/o post 中的建议)。
  • 我们尝试为 DefaultAppPool 和 Network Service 帐户使用“runas”运行 certmgr,但是当提示输入密码时,我们不知道密码是什么(空白密码不起作用)。我什至按照此处的建议查找了 DefaultAppPool 密码,根据该输出,密码为空。

到目前为止,没有任何效果(除了以管理员身份运行应用程序之外),我们不知道下一步该尝试什么。我们到处寻找某种“微软官方部署指南”,但所有这些都是关于如何在本地开发环境中使始终加密工作的教程,而不是关于服务器部署。

sql-server iis sql-server-2016 always-encrypted

0
推荐指数
1
解决办法
1331
查看次数