小编Jon*_*att的帖子

捕获"超出最大请求长度"

我正在编写一个上传函数,并且httpRuntime在web.config中使用大于指定最大大小的文件时捕获"System.Web.HttpException:超出最大请求长度"时遇到问题(最大大小设置为5120).我正在使用一个简单<input>的文件.

问题是在上传按钮的click-event之前抛出了异常,并且异常发生在我的代码运行之前.那么如何捕获和处理异常呢?

编辑:异常立即抛出,所以我很确定它不是由于连接速度慢导致的超时问题.

c# asp.net httpexception

110
推荐指数
6
解决办法
14万
查看次数

在jquery回调中调用时,TypeScript"this"作用域问题

我不确定在TypeScript中处理"this"范围的最佳方法.

这是我转换为TypeScript的代码中常见模式的示例:

class DemonstrateScopingProblems {
    private status = "blah";
    public run() {
        alert(this.status);
    }
}

var thisTest = new DemonstrateScopingProblems();
// works as expected, displays "blah":
thisTest.run(); 
// doesn't work; this is scoped to be the document so this.status is undefined:
$(document).ready(thisTest.run); 
Run Code Online (Sandbox Code Playgroud)

现在,我可以将呼叫改为......

$(document).ready(thisTest.run.bind(thisTest));
Run Code Online (Sandbox Code Playgroud)

......确实有效.但它有点可怕.这意味着代码可以在某些情况下编译和工作正常,但如果我们忘记绑定范围,它将会中断.

我想在类中做一个方法,这样在使用类时我们不需要担心"this"的作用范围.

有什么建议?

更新

另一种方法是使用胖箭头:

class DemonstrateScopingProblems {
    private status = "blah";

    public run = () => {
        alert(this.status);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一种有效的方法吗?

this typescript

105
推荐指数
3
解决办法
5万
查看次数

在为类方法使用胖箭头语法时,我可以使用TypeScript重载吗?

我已经从传统形式转换了一些类:

class TestOverloads {
    private status = "blah";
    public doStuff(selector: JQuery);
    public doStuff(selector: string);
    public doStuff(selector: any) {
        alert(this.status);
    }
}
Run Code Online (Sandbox Code Playgroud)

改为使用箭头函数表达式:

class TestOverloads2 {
    private status = "blah";
    public doStuff = (selector: any) => {
        alert(this.status);
    }
}
Run Code Online (Sandbox Code Playgroud)

以便在回调中使用类方法时避免使用作用域问题(请参阅此处了解背景信息).

我无法弄清楚如何重新创建我的重载函数签名.使用胖箭时如何编写重载?

typescript arrow-functions

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

在属性构造函数中使用可选参数时,属性参数必须是常量错误

谁能解释为什么这段代码有效:

public class AdministratorSettingValidationAttribute : Attribute
{
    public AdministratorSettingValidationAttribute(AdministratorSettingDataType administratorSettingDataType)
    {
        DataType = administratorSettingDataType;
    }

    public AdministratorSettingValidationAttribute(AdministratorSettingDataType administratorSettingDataType, Type enumerationType)
    {
        DataType = administratorSettingDataType;
        EnumerationType = enumerationType;
    }
}
Run Code Online (Sandbox Code Playgroud)

...但重构它以使用可选参数:

    public AdministratorSettingValidationAttribute(AdministratorSettingDataType administratorSettingDataType, Type enumerationType = null)
    {
        DataType = administratorSettingDataType;
        EnumerationType = enumerationType;
    }
Run Code Online (Sandbox Code Playgroud)

...导致编译时错误:" 属性参数必须是属性参数类型的常量表达式,typeof表达式或数组创建表达式 ".

.net c# visual-studio-2010

17
推荐指数
2
解决办法
4769
查看次数

尽管急于获取,但仍“尝试对分离的实体进行延迟加载导航属性”

我正在使用启用了延迟加载的Entity Framework Core 2.1.2,并使用AsNoTracking执行查询。我正在使用Include来引入我的导航属性(一个集合)。

如果我所有的实体中至少有一个孩子,则一切正常。

但是,如果我的任何实体都没有子代,那么我会得到一个错误:

System.InvalidOperationException:生成警告“ Microsoft.EntityFrameworkCore.Infrastructure.DetachedLazyLoadingWarning”的错误:尝试对类型为“ ParentProxy”的分离实体延迟加载导航属性“ Children”。分离的实体或使用'AsNoTracking()'加载的实体不支持延迟加载。

这是问题的重现(使用NuGet引入Microsoft.EntityFrameworkCore 2.1.2,Microsoft.EntityFrameworkCore.Proxies 2.1.2,Microsoft.EntityFrameworkCore.InMemory 2.1.2之后,可以从控制台应用程序运行该问题):

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;

namespace LazyLoadingIssue
{
    public class Parent
    {
        public int Id { get; set; }
        public string ParentName { get; set; }
        public virtual ICollection<Child> Children { get; set; }
    }

    public class Child
    {
        public int Id { get; set; }
        public int ParentId { get; set; }
        public virtual Parent Parent { get; set; }
        public string …
Run Code Online (Sandbox Code Playgroud)

ef-core-2.1

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

向匿名类添加额外属性

有没有办法为匿名类添加额外的属性(或创建具有额外属性的新实例)?

string cssClasses = "hide";
object viewData = new { @class = cssClasses };
if (suppliedId != null)
{
  // add an extra id property to the viewData somehow...
  // desired end result is { @id = suppliedId, @class = cssClasses }
}
// ... code will be passing the viewData as the additionalViewData parameter in asp.mvc's .EditorFor method
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

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

如何组合两个表达式?

我正在尝试构建一个将应用于IQueryable集合的表达式.

我可以构建一个这样的表达式:

[TestClass]
public class ExpressionTests
{
    private IQueryable<MyEntity> entities;

    private class MyEntity
    {
        public string MyProperty { get; set; }
    }

    [TestInitialize]
    public void Setup()
    {
        entities = new[]
                    {
                        new MyEntity {MyProperty = "first"}, 
                        new MyEntity {MyProperty = "second"}
                    }.AsQueryable();
    }

    [TestMethod]
    public void TestQueryingUsingSingleExpression()
    {
        Expression<Func<MyEntity, bool>> expression = e => e.MyProperty.Contains("irs");
        Assert.AreEqual(1, entities.Where(expression).Count());
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我想分开表达式的两个部分:

[TestMethod]
public void TestQueryingByCombiningTwoExpressions()
{
    Expression<Func<MyEntity, string>> fieldExpression = e => e.MyProperty;
    Expression<Func<string, bool>> operatorExpression = e => e.Contains("irs");
    // …
Run Code Online (Sandbox Code Playgroud)

c# linq linq-to-nhibernate

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

来自Typescript jsdoc的Visual Studio intellisense不使用胖箭头函数

打字稿intellisense工作正常:

class SampleClass {
    /**
     * Does stuff
     *
     * @param blah stuff needing done 
     */
    public doStuff(blah: string) {
    }
}

var sample = new SampleClass();
// intellisense works correctly and shows parameter description:
sample.doStuff("hello"); 
Run Code Online (Sandbox Code Playgroud)

但是切换到使用胖箭头似乎打破了jsdoc intellisense(方法签名仍然出现,但jsdoc描述都没有):

class SampleClass2 {
    /**
     * Does stuff
     *
     * @param blah stuff needing done 
     */
    public doStuff = (blah: string) => {
    }
}

var sample2 = new SampleClass2();
// intellisense gives the method signature still but no longer picks up any …
Run Code Online (Sandbox Code Playgroud)

jsdoc visual-studio-2012 typescript arrow-functions

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

配置 WCF 客户端绑定以在 dotnet core 2.2 中使用 X509 证书

我正在尝试将旧的 WCF 客户端转换为 dotnet core。我成功地从 wsdl 生成了代理,并一直在尝试配置它们,以便我可以成功调用端点。根据一些谷歌搜索,似乎在 dotnet core 下我需要从代码配置我的 WCF 客户端。

以下是旧应用程序 web.config 中的 WCF 配置部分:

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <behaviors>
    <endpointBehaviors>
      <behavior name="clientEndpointCredential">
        <clientCredentials>
          <clientCertificate storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectName" findValue="CERTNAME" />
        </clientCredentials>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <bindings>
    <basicHttpBinding>
      <binding name="OUR_Customer_OUTBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="Transport">
          <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="https://the-full-url" behaviorConfiguration="clientEndpointCredential" binding="basicHttpBinding" bindingConfiguration="OUR_Customer_OUTBinding" contract="CustomerInterface.OUR_Customer_OUT" name="HTTPS_Port" …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-binding wcf-security .net-core

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

使用 msbuild 列出目录的内容

我正在尝试调试在我们的 TFS 构建代理上运行的 msbuild 脚本。我对构建代理服务器没有权限。

有没有一种方法可以向我的 msbuild 脚本(“消息”或类似脚本)添加一些调试功能,以输出给定目录中所有文件的列表?

msbuild

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

用Meteor运行夜间流程

我正在使用meteor编写应用程序,我需要在某个时间每晚运行一个进程.此过程将需要访问Meteor的Mongo数据库,并且也将受益于其他Meteor功能.

是否可以按计划运行流星过程或某种类型的任务?或者我需要使用不同的堆栈来实现我想要的吗?

meteor

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

有没有办法在Visual Studio中使用IE8安装TypeScript

我正在尝试将TypeScript(0.9.5)安装到我的工作PC上的Visual Studio 2012中,它只有IE8(我知道,我知道,这是一种可怕的事态......).

安装过程无法完成,并说我应该先安装IE10.

有没有人有任何变通办法可以让我在保持IE8的同时安装它?

visual-studio-2012 typescript

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