我在标准的ASP.NET MVC项目中向ASP.NET身份模型添加了电子邮件验证.以下行导致AccessViolationException:
callbackUrl = Url.Action("ConfirmEmail", "Account", confirmModel, Request.Url.Scheme);
Run Code Online (Sandbox Code Playgroud)
更新: 由于问题无法解释,它就消失了.我会试着弄清楚是什么让它消失了.令我担心的是,我不知道解决方案有任何重大变化.
用于注册用户的完整帐户控制器方法如下所示:
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
ApplicationUser user = new ApplicationUser { UserName = model.Email, Email = model.Email };
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
string callbackUrl;
try
{
string requestScheme = Request.Url.Scheme;
object confirmModel = new { userId = user.Id, code = code };
callbackUrl = Url.Action("ConfirmEmail", "Account", confirmModel, Request.Url.Scheme); // …Run Code Online (Sandbox Code Playgroud) 如今,可以使用 Swagger 对 API 进行版本控制,并且周围的大多数事情都可以完美地工作。我在这里真正缺少的是让任何 Swagger UI 用户都清楚 API版本已被标记为已弃用的可能性。
此处描述了 aspnetcore 中的 API 弃用。我的期望是在 API 组名称旁边有一个图标或标签,上面写着“OBSOLETE”或“DEPRECATED”。
Swashbuckle Swagger ASPNET.Core github 项目问题跟踪器建议在 SO 上打开功能请求。
编辑:
使用 ApiVersion 属性将整个控制器标记为已弃用。如果将控制器标记为 [已过时],则所有方法均呈灰色且文本带有删除线。但这不是我想要的。我不想将我的代码库标记为[已过时]。我想将特定的 API 版本标记为已弃用,以便人们知道他们应该切换到较新的版本。
[ApiVersion("1", Deprecated = true)]
[Route("v{version:apiVersion}/[controller]")]
[Authorize("my.auth.policy")]
[ApiController]
public class MyApiController
{
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
我当前的解决方法是这样的:在我的 Startup 中,我添加 swaggerUI 并在 swagger 端点下拉显示上执行自定义格式设置。
app.UseSwagger();
app.UseSwaggerUI(options =>
{
foreach (ApiVersionDescription apiVersionDescription in apiVersionDescriptionProvider.ApiVersionDescriptions.OrderByDescending(a => a.ApiVersion))
{
string isDeprecated = apiVersionDescription.IsDeprecated ? " (DEPRECATED)" : string.Empty;
options.SwaggerEndpoint($"{Configuration["PathBase"]}/swagger/{apiVersionDescription.GroupName}/swagger.json",
$"{apiVersionDescription.GroupName.ToUpperInvariant()}{isDeprecated}"); …Run Code Online (Sandbox Code Playgroud) 我认为该RunAsync方法将a CancellationToken作为参数很好。不幸的是,根据我的观察,我从未被取消。
当然,取消RunAsync方法并调用OnCloseAsync将是多余的。我仍然想知道取消是何时发生的。
我是否应该编写一些其他代码以在客户端中提供有效的Stop()方法?我本来希望RunAsync中的cancelestToken实际上会被取消;-)
我的服务结构服务代码:
/// <summary>
/// This is the main entry point for your service instance.
/// </summary>
/// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param>
protected override async Task RunAsync(CancellationToken cancellationToken)
{
// TODO: Replace the following sample code with your own logic
// or remove this RunAsync override if it's not needed in your service.
long iterations = …Run Code Online (Sandbox Code Playgroud) 场景:
我需要为同一 Web应用程序(appdomain)中的相同接口定义提供不同的接口实现,但要提供不同的“作用域”。
想象这样一个简单的分层Web内容结构(如果您不熟悉SharePoint):
RootWeb (SPSite) (ctx here)
|______SubWeb1 (SPWeb) (ctx here)
|______SubWeb2 (SPWeb)
|______SubWeb3 (SPWeb)
|_______SubWeb3.1 (SPWeb) (ctx here)
|_______SubWeb3.2 (SPWeb)
Run Code Online (Sandbox Code Playgroud)
RootWeb,SubWeb1和SubWeb3.1提供上下文。也就是说,我实现了一个AppIsolatedContext类,该类特定于某个层次结构级别。如果级别不提供上下文,则它从父节点继承上下文,依此类推。例如,SubWeb3将从RootWeb继承其上下文。但是,SubWeb3.1提供了自己的隔离上下文。
隔离的上下文只是静态的ConcurrentDictionary。
好的,到目前为止很好。现在关于Autofac(我是Autofac和任何其他DI容器的新手,尽管不了解IoC原理)...我不确定如何正确设置它以正确处理对象。实际上,这不应该是什么大问题,因为对象(一旦创建)就应该一直存在,直到appdomain被回收(将它们视为“每个隔离上下文单例”)为止。
我倾向于做这样的事情:
RootWeb (SPSite) (ctx here)
|______SubWeb1 (SPWeb) (ctx here)
|______SubWeb2 (SPWeb)
|______SubWeb3 (SPWeb)
|_______SubWeb3.1 (SPWeb) (ctx here)
|_______SubWeb3.2 (SPWeb)
Run Code Online (Sandbox Code Playgroud)
当然,我的应用程序不限于这些“上下文单例”实例。我也将按请求提供生命周期实例..但这就是ASP.NET集成模块对的吗?我希望它们也可以无缝集成到SharePoint(2013)中:)
所以我的问题是我提出的建议还好吗?还是需要弄脏我的手?如果是这样,那么某个方向将是惊人的 ...
浏览Autofac的文档时,我偶然发现了其多租户功能。我相信这也可能适合我的目的。.有人可以确认吗?
// For completeness.. a dummy page which creates a "dummy" context
public partial class _Default : Page
{
private static AppIsolatedContext _dummyContainer = new …Run Code Online (Sandbox Code Playgroud) 我正在尝试发布此数据:
my_tests,SNR=533033200650344358002D00,TNR=test HelloWorld=123 1495179651177999872
my_tests,SNR=533033200650344358002D00,TNR=test HelloWorld=444 1495179651203000064
Run Code Online (Sandbox Code Playgroud)
该帖子的网址看起来像
http://influx.local:8086/write?db=testdb&u=myuser&p=myasswd
Run Code Online (Sandbox Code Playgroud)
原始回应:
HTTP/1.1 400 Bad Request
Content-Type: application/json
Request-Id: 4a1802d2-3ebd-11e7-8030-000000000000
X-Influxdb-Version: 1.1.4
Date: Mon, 22 May 2017 07:07:17 GMT
Content-Length: 147
{"error":"partial write:\nunable to parse 'my_tests,SNR=533033200650344358002D00,TNR=test HelloWorld=123 1495179651177999872\r': bad timestamp"}
Run Code Online (Sandbox Code Playgroud)
时间戳对我来说似乎有效。
如果我只发布一行(而不是上面的示例中的两行),那么效果很好!
我还想知道时间戳记之后错误日志的末尾“ \ r”在做什么。因为我写的是“ \ n”。
有趣的是,直到最近我才对InfluxDB进行写操作没有任何问题。不涉及版本升级。
我正在运行InfluxDB 1.x(不确定确切的版本)
为了解决这个问题,如果我完全省略了时间戳(出于测试目的),它仍然不起作用:
{"error":"partial write:\nunable to parse 'my_tests,SNR=533033200650344358002D00,TNR=test HelloWorld=123\r': invalid number"}
Run Code Online (Sandbox Code Playgroud)
更新:出于测试目的,我安装了InfluxDb 1.2.7(Windows Standalone)
有效负载与以前相同
my_tests,SNR=533033200650344358002D00,TNR=test HelloWorld=123 1439856000
my_tests,SNR=533033200650344358002D00,TNR=test HelloWorld=444 1439856001
Run Code Online (Sandbox Code Playgroud)
大量报告返回:
HTTP/1.1 400 Bad Request
Content-Type: application/json
Request-Id: eca5283a-3ec4-11e7-8029-000000000000 …Run Code Online (Sandbox Code Playgroud) 运行此程序将在四核系统中咀嚼25%的CPU功率.所以基本上一些东西正在全力以赴.我把它缩小到了消费者,然而按下"x"时负载不会停止,这应该终止我的消费者.
我的代码
internal class TestBlockingCollectionConsumerProducer2
{
private int _itemCount;
internal void Run()
{
BlockingCollection<string> blockingCollection = new BlockingCollection<string>();
// The token source for issuing the cancelation request.
CancellationTokenSource cts = new CancellationTokenSource();
// Simple thread waiting for a Console 'x'
Task.Factory.StartNew(() =>
{
if (Console.ReadKey().KeyChar == 'x')
{
cts.Cancel();
}
});
// start producer
Task.Factory.StartNew(() => Produce(blockingCollection, cts.Token));
// start multiple consumers
const int THREAD_COUNT = 5;
for (int i = 0; i < THREAD_COUNT; i++)
{
Task.Factory.StartNew(() => Consume(blockingCollection, …Run Code Online (Sandbox Code Playgroud)