默认情况下我需要进行多项选择,因此用户无需按住ctrl.非常感谢一些帮助,谢谢.
我正在尝试重构一些代码,以通过startup.cs中的映射服务使用.NET Core依赖注入.我想在这里注入一个IRequestDatabaseLogger而不是新建它.但是它需要构造函数中的上下文.我怎样才能做到这一点?甚至没有DI框架甚至可能吗?
public class ActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
var requestDatabaseLogger = new RequestDatabaseLogger(context);
long logId = requestDatabaseLogger.Log();
context.HttpContext.AddCurrentLogId(logId);
base.OnActionExecuting(context);
}
}
Run Code Online (Sandbox Code Playgroud) 所以我的解决方案编译但是当我运行它时,我在运行.NET 4.6.1的类库中遇到错误.
System.TypeLoadException:'无法从程序集'System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'加载类型'System.Data.Common.DbProviderFactories'.
有什么建议?
编辑:
完成错误:
$ exception {System.TypeLoadException:无法从程序集'System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'加载类型'System.Data.Common.DbProviderFactories'.在System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(系统类型,对象键,Func
3 handleFailedLookup) at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetServices(Type type, Object key) at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey键,Func2 valueFactory) at System.Linq.Enumerable.SelectManySingleSelectorIterator
2.MoveNext())System.Linq.Enumerable.ConcatIterator1.MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator
2.MoveNext()at System .Linq.Enumerable.ConcatIterator1.MoveNext() at System.Linq.Enumerable.<OfTypeIterator>d__32
1.MoveNext()at System.Collections.Generic.List1.AddEnumerable(IEnumerable
1 enumerable)at System.Linq.Enumerable.ToList [TSource](IEnumerable1 source) at System.Data.Entity.Infrastructure.DependencyResolution.InternalConfiguration.Lock() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1() at System.Lazy
1.ViaFactory(LazyThreadSafetyMode mode)at System.Lazy 1.CreateValue1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy
( )System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration()at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection,DbCompiledModel model)at XYConfigurationModule.ConfigurationContainer..ctor(String nameOrConnectionString)} System.TypeLoadException
更新:如果我改变返回新的 OkObjectResult(token); 返回 Ok("test"); 那么它不是空的。
要使用 API,您必须调用 AuthenticateAsync,它会创建并返回一个令牌。
[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> AuthenticateAsync([FromBody]string apiKey)
{
return await StopwatchLogger.LogExecutionTime($"Authenticate user: {apiKey}", async () =>
{
EnsureValidLoginRequest(apiKey);
//Validate user credentials
AuthenticationInfo authenticationInfo = await _authenticationService.AuthenticateUser(apiKey);
if (!authenticationInfo.IsAuthenticated)
{
throw new RestApiExceptionNoLogging(ErrorCode.AuthenticationInvalidApiKey, "");
}
//Login current user and get the created token with claims identifying current user
Token token = _authenticationService.LoginApiUser(HttpContext, authenticationInfo.SystemUser);
return new OkObjectResult(token);
});
}
Run Code Online (Sandbox Code Playgroud)
令牌创建正确,据我所知,一切都和以前一样,除了响应正文变空。不会抛出任何错误。
编辑:添加startup.cs
public class Startup
{
private const string LogText = "An error occurred during …
Run Code Online (Sandbox Code Playgroud) 我们希望以编程方式将图像批量转换为 PDF。到目前为止,我们似乎将使用 iTextSharp,但我们在处理带有剪切路径的 JPG 图像时遇到了问题。我们在测试中使用以下代码:
using (FileStream fs = new FileStream(output, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (Document doc = new Document())
{
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
{
doc.Open();
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(source);
image.SetAbsolutePosition(0, 0);
doc.SetPageSize(new iTextSharp.text.Rectangle(0, 0, image.Width, image.Height, 0));
doc.NewPage();
writer.DirectContent.AddImage(image,false);
doc.Close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
JPG 图像中的剪切路径似乎只是被丢弃了。有没有办法保留剪切路径?此外,在调用 AddImage 时,有一个 InlineImage 选项,有人知道这是做什么的吗?
c# ×4
asp.net-core ×2
.net ×1
asp.net ×1
clipping ×1
itext ×1
itextsharp ×1
jpeg ×1
jquery ×1
jquery-ui ×1
selectable ×1