小编Isa*_*vin的帖子

Dot Net Core 中的 MultipartMemoryStream

我有一个 .Net 4.5.2 应用程序,我要迁移到 Dot Net Core。此应用程序允许用户上传带有元数据(Angular 客户端)的文件,Api 将处理请求并处理文件。这是执行此操作的现有代码。

应用程序接口

[HttpPost]
[Route("AskQuestions")]
public void ProvideClarifications(int id)
{
  var user = base.GetUserLookup();
  if (user != null)
  {
    var streamProvider = new MultiPartStreamProvider();
    IEnumerable<HttpContent> parts = null;
    Task.Factory
        .StartNew(() => parts = Request.Content.ReadAsMultipartAsync(streamProvider).Result.Contents,
            CancellationToken.None,
            TaskCreationOptions.LongRunning,
            TaskScheduler.Default)
        .Wait();

        // do some stuff with streamProvider.FormData
  }
}
Run Code Online (Sandbox Code Playgroud)

处理文件和元数据的提供者

public class MultiPartStreamProvider : MultipartMemoryStreamProvider
{
    private string _originalFileName = string.Empty;
    public Dictionary<string, object> FormData { get; set; }

    public byte[] ByteStream { get; set; } …
Run Code Online (Sandbox Code Playgroud)

multipartform-data angularjs .net-core

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

在 Unity 中使用 IOptions

我有一个从 ASP.Net Core(针对 4.5)和一个 4.5 Web 应用程序引用的类库,我想共享应用程序设置。我在 4.5 端使用 Unity 进行 DI,在 Core 端使用 Core Bootstrapping。在核心方面,我像这样注册了一种我的应用程序设置

services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
Run Code Online (Sandbox Code Playgroud)

然后我像这样引用 AppSettings

private readonly AppSettings _appSettings;
public SubmissionRepository(PricingContext dbContext, IMapper mapper, IOptions<AppSettings> appSettings)
{
     _appSettings = appSettings;
}
Run Code Online (Sandbox Code Playgroud)

我想在 4.5 端注册我的服务,我能够在 WebApiConfig.cs 中使用 Unity 进行此操作

container.RegisterType<AppSettings>(new InjectionFactory(o => BuildAppSettings()));
Run Code Online (Sandbox Code Playgroud)

BuildAppSettings 只是使用 ConfigurationManager 填充该类型的实例(不确定这是否是正确的方法)

但是我在运行时遇到异常

无法将“.Core.Integration.Models.AppSettings”类型的对象转换为“Microsoft.Extensions.Options.IOptions`1[Core.Integration.Models.AppSettings]”。

我猜我需要以某种方式将 IOptions 实例放入我的容器中,但不确定如何执行此操作。有没有首选/更好的方法来做到这一点?

.net c# dependency-injection unity-container

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

将自定义对象列表传递给 SQL Server 存储过程

我希望仅通过一次存储过程调用来传递自定义对象列表。这是对象

 public class OGFormResponse
{
    public string Response {get; set;}
    public OGFormLabelVO FormLabel {get; set;}
}
    public class OGFormLabelVO
{
    public int OGFormLabelKey {get; set;}
    public string FormType {get; set;}
    public string LabelText {get; set;}
    public string ControlName {get; set;}
    public string DisplayStatus {get; set;}
    public string LabelType = {get; set;}
    public bool IsActive {get; set;}
    public string LabelParentControlName {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

这是数据库关系

CREATE TABLE [dbo].[OGFormLabels](
[OGFormLabelKey] [int] IDENTITY(1,1) NOT NULL,
[OGFLText] [nvarchar](max) NULL,
[OGFLControlName] [nvarchar](50) NOT NULL,
[OGFLIsActive] [bit] …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server stored-procedures table-valued-parameters

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

ConvertTo-SecureString在不同的服务器上提供不同的体验

我遇到了从远程服务器上的XML文件创建凭据对象的问题.这是我用来测试的代码

XML文件

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
     <TN RefId="0">
        <T>Selected.System.Management.Automation.PSCredential</T>
        <T>System.Management.Automation.PSCustomObject</T>
        <T>System.Object</T>
     </TN>
     <MS>
        <S N="UserName">domain\username</S>
        <S N="Password">01000000d08c9ddf0115d1118c7a00c04fc297eb010000001f19c6a42b9b0d48af2c531892e737ce000000000200000000001066000000010000200000006fb8862fbaea7b83cd2bcab35d7a8c8b4d71b7764c2a91d68eb3873864bc9d83000000000e8000000002000020000000fcbcc5552c3eb40ec337594f8286b08780709c1ac583d4679dcd7a3f5a92441b20000000c8e274811ed7a411b6741b2c65a67363f6aef380e684d13218d1ecc1281dfdb940000000c7279e81e21a1e57eed7da61e969f34fe2adf3d7e534bb5e10b89902adf4fdf20a69ec7e9b9e56dab512c789043a3b2cf0611e3b4893658b7c20f7892ce0ddfd</S>
</MS>
Run Code Online (Sandbox Code Playgroud)

PowerShell代码

    $cred = Import-Clixml "Payload\DeploymentCredential.xml"
    write-host $cred
    $cred.Password = ConvertTo-SecureString $cred.Password 
    write-host $cred.Password
    $Credential = New-Object System.Management.Automation.PsCredential($cred.UserName, $cred.Password)
    write-host $Credential.GetNetworkCredential().password
Run Code Online (Sandbox Code Playgroud)

在一台服务器(我的本地机器)上它完全正常,但在远程服务器上,我收到此错误

Key not valid for use in specified state.    
+ CategoryInfo          : InvalidArgument: (:) [ConvertTo-SecureString], CryptographicException
+ FullyQualifiedErrorId : ImportSecureString_InvalidArgument_CryptographicError,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
Run Code Online (Sandbox Code Playgroud)

两者都有相同版本的PowerShell(3.0 Build -1 Revision -1),所以我不确定是什么问题.

powershell powershell-3.0

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