我想知道是否有可能从MVC控制器返回一个带有内容的错误请求?我能够做到这一点的唯一方法是在throw HttpException这里我不能设置任何内容.试过这种方法,但由于一些奇怪的原因,我总是得到回报.是否有可能做到这一点?
public class SomeController : Controller
{
[HttpPost]
public async Task<HttpResponseMessage> Foo()
{
var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
response.Content = new StringContent("Naughty");
return response;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个ajax请求,我故意从我的服务器端代码失败来触发错误处理事件.我想知道是否有可能获得它尝试的URL?我想获取该URL并将其注入超链接并重试该请求.
这可能吗?
编辑
我能够看到尝试的URL请求通过FireBug和检查jqxhr对象,console.dir()并且似乎无法找到任何有助于我识别它试图调用的URL的内容.理想情况下,不希望存储全局变量,希望从参数中获取此信息.
在此先感谢,O.
$.ajax({
type: 'get',
url: 'somewhere/foo',
context: this,
success: this.mySuccess,
error: this.myError,
cache: false
});
myError = function (jqXhr, textStatus) {
alert(jqXhr.url); //Get url of failed request and inject it into hyper link?
};
Run Code Online (Sandbox Code Playgroud) 如何对自定义DelegatingHandler进行单元测试?我有以下但它抱怨innerHandler未设置.
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://foo.com");
var handler = new FooHandler()
{
InnerHandler = new FooHandler()
};
var invoker = new HttpMessageInvoker(handler);
var result = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
Assert.That(result.Headers.GetValues("some-header").First(), Is.Not.Empty, "");
Run Code Online (Sandbox Code Playgroud) 我想知道是否有人在使用Swagger/ Swashbuckle 5.0.1记录单个操作时遇到了解决方法,该操作可能有多个操作.例如,请执行以下操作:
api/products
api/products?productType='cheese'
Run Code Online (Sandbox Code Playgroud)
在尝试生成文档时,我收到错误,表明不支持此操作.但是,Swagger文档建议通过合并进行解决方法.
我不明白它们的含义以及如何去做.有人能提供任何信息吗?
我能够在其文档中找到的唯一解决方法是执行以下操作(使用第一个条目解析):
c.ResolveConflictingActions(x => x.First());
Run Code Online (Sandbox Code Playgroud)
这不是理想的,因为从API的角度来看,我希望所有变体都存在/可见.
有人知道如何解决这个问题吗?
在PowerShell中键入以下命令时进行复制.
dir iis:\sslbindings
Run Code Online (Sandbox Code Playgroud)
我在Microsoft TechNet上遇到过这个没有解决问题的页面.
调用命令时,我收到错误
无法枚举SSL绑定
显然是由于注册表损坏?
我使用的是最新版本的Swashbuckle 5.1.3,并注意到有一个新属性SwaggerResponse允许您记录每个响应代码的响应类型.例如:
(https://github.com/domaindrivendev/Swashbuckle/issues/175 <可能证明是有用的).
/// <summary>
/// Lovely.
/// </summary>
/// <param name="blah">Blah blah blah.</param>
/// <returns>Something special.</returns>
/// <response code="200">OK very nice.</response>
/// <response code="400">Invalid request.</response>
[SwaggerResponse(HttpStatusCode.OK, "A", typeof(Foo))]
[SwaggerResponse(HttpStatusCode.BadRequest, "B", typeof(Bar))]
public IHttpActionResult Get(string blah)
{
// Some code
}
Run Code Online (Sandbox Code Playgroud)
初始响应类记录正确,但在显示表的情况下进一步向下"Response Messages",响应模型为空(对于400 Bad Request).无法在屏幕上看到记录其他响应类型的任何位置.
我想知道是否有更简单的方法(更好的方式)检查500状态代码?
我能想到这样做的唯一方法是:
var statusCodes = new List<HttpStatusCode>()
{
HttpStatusCode.BadGateway,
HttpStatusCode.GatewayTimeout,
HttpStatusCode.HttpVersionNotSupported,
HttpStatusCode.InternalServerError,
HttpStatusCode.NotImplemented,
HttpStatusCode.ServiceUnavailable
};
if (statusCodes.Contains(response.StatusCode))
{
throw new HttpRequestException("Blah");
}
Run Code Online (Sandbox Code Playgroud)
我注意到这些是500种类型:
我试图定义一个数组并循环遍历它,查找消息包含数组中元素的痕迹。是否有可能做到这一点?例如:
let myIds = datatable (name: string)
[
"111",
"222",
"333",
];
forach (id in myIds)
{
traces
| where message contains id
}
Run Code Online (Sandbox Code Playgroud)
我知道这不是上面的正确语法,但希望它能解释我想要实现的目标。简而言之,循环遍历数组并在我的日志(特别是跟踪)中执行查找。
我正在使用代码优先方法,并且尝试更改 EF 创建表的行为。我有两个简单的课程:
注意:我每次都会删除并重新创建数据库。这在现实世界中不会发生,但为了测试,我尝试拦截创建并强制 EF 按照我的设想创建数据库。
public class Person
{
public int PersonId { get; private set; }
public string Forename { get; set; }
}
public class Officer : Person
{
public int OfficerId { get; private set; }
public bool IsManager { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的 OnModelCreating() 事件中,我有以下内容:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<Person>().HasKey(x => x.PersonId);
modelBuilder.Entity<Person>().ToTable("Person");
modelBuilder.Entity<Officer>().HasKey<int>(x => x.OfficerId);
modelBuilder.Entity<Officer>().ToTable("Officer");
}
Run Code Online (Sandbox Code Playgroud)
问题是当我的数据库创建时,它创建的表如下:
表:人员 PersonId INT PK Forename nvarchar(50)
表: 官员 PersonId INT PK、FK …
希望定义一个变量来保存查询的输出,然后从中查询跟踪。像这样的东西:
let start=datetime("2020-10-07T15:01:00.000Z");
let end=datetime("2020-10-09T13:20:00.000Z");
let timeGrain=1h;
let dataset = dependencies
| where timestamp > start and timestamp < end and ['type'] == 'HTTP' and success == false
| where name contains "mgw/capture"
| project operation_ParentId
traces
| join kind=inner(dataset) on operation_ParentId
Run Code Online (Sandbox Code Playgroud)
这可能吗?
c# ×5
kql ×2
ajax ×1
api-doc ×1
asp.net-mvc ×1
bad-request ×1
binding ×1
get ×1
iis ×1
jquery ×1
jqxhr ×1
powershell ×1
ssl ×1
swagger ×1
swashbuckle ×1
unit-testing ×1