草庐IT

cake_core_method_cache

全部标签

c# - .NET Core UseCors() 不添加 header

这将是HowdoesAccess-Control-Allow-Originheaderwork?的副本,但那里的方法也不适合我。我希望我只是遗漏了一些东西。我试图在我的.NETCoreWebAPI的响应中获取一个Access-Control-Allow-Originheader,我正在通过AJAX访问它。我试过很多东西。除非另有说明,否则所有内容都在Startup.cs文件中。方法一根据MicrosoftDocumentation:publicvoidConfigureServices(IServiceCollectionservices){//Adddatabaseservices.

c# - 日期时间类型的所有属性上的 EF CORE 2.1 HasConversion

我之前在读取实体时使用DateTimeKindEntityMaterializerSource(Git)将所有DateTime转换为UTC,因为未指定默认值。对于EFcore2.1,DateTimeKindEntityMaterializerSource不再有效,但我们实际上可以这样做builder.Entity().Property(e=>e.CreatedDate).HasConversion(v=>v,v=>DateTime.SpecifyKind(v,DateTimeKind.Utc));但是,我有DateTime的许多属性,我想是否有一种方法可以对DateTime类型的所有属

c# - Resharper 中的警告 "Return value of pure method is not used"

我有一个快速的问题,关于我正在工作的c#项目中从VisualStudio中的Resharper收到的警告。警告是:"ReturnValueofpuremethodisnotused"发生这种情况的方法如下:privatestaticboolFilePathHasInvalidChars(stringuserInputPath){try{//thisiswherethewarningoccurs:Path.GetFullPath(userInputPath);}catch(Exceptione){Log.Error(String.Format("TheProgramfailedtorun

c# - 多线程,Task.Run 错误 'The call is ambiguous between the following methods or properties'

当我尝试构建项目时,显示以下错误消息。Thecallisambiguousbetweenthefollowingmethodsorproperties:'System.Threading.Tasks.Task.Run(System.Action)'and'System.Threading.Tasks.Task.Run(System.Func)'我该如何解决这个问题?publicstaticclassMaintananceManager{privatestaticThreadSafeSocialMediaListPostList=newThreadSafeSocialMediaList(

c# - 获取在 .NET Core 中实现接口(interface)的所有类型

使用反射,如何获取在.NETCore中实现某些特定接口(interface)的所有类型?我注意到.NET4.6中可用的方法不再可用。例如,这段代码不起作用。vartype=typeof(IMyInterface);vartypes=AppDomain.CurrentDomain.GetAssemblies().SelectMany(s=>s.GetTypes()).Where(p=>type.IsAssignableFrom(p));它抛出Thename'AppDomain'doesnotexistinthecurrentcontext错误。 最佳答案

c# - 选择 webApi 模板时如何将 ASP.Net 身份添加到 Asp.Net Core?

我创建了一个.NETCore项目,其中选择了WebApi模板,不包括身份验证。我想在其中添加ASP.NET身份以进行基于角色的授权。我怎样才能做到这一点? 最佳答案 编辑:这回答了问题,但总的来说我同意对上述问题的评论-JWT不记名token最适合API,最好在为您的用例决定最佳方法之前了解该选项。原始答案这将为您提供一个具有aspnet核心身份的熊骨webapi,首先创建您的项目(假设您已经创建了一个新文件夹并且您在其中):dotnetnewwebapi添加aspnet核心标识:dotnetaddpackageMicrosoft.

c# - Azure Function,EF Core,无法加载 ComponentModel.Annotations 4.2.0.0

我已经创建了几个.NetStandard2.0库,通过控制台应用程序测试了执行情况,还有一些测试-一切都很好。转到azure函数,并得到以下运行时错误:然后我尝试将该特定版本下载到API函数项目中:我使用的是VisualStudio版本15.7.0预览版5.0。我已将AzureFunctions更新到4.7...因为控制台和测试项目是-并且这些工作正常。在这方面待了太多小时..所以我希望这个决议不是什么疯狂的事情。EfCore2.1.0-rc1-final也在其中。对Required、MaxLength、NotMapped使用数据注释。图形错误说:Microsoft.EntityFra

c# - .NET Core 2.2 目标进程退出时未引发 CoreCLR 启动事件错误

我想调试一个基于.NETCore2.2的空WebApi项目。我安装了“Core2.2SDKx86”并将目标框架更改为2.2:netcoreapp2.2当我开始调试这个项目时,IIS启动了,但是在路由api/values中我什么也没看到(它永远加载)并且我得到这个错误:ThetargetprocessexitedwithoutraisingaCoreCLRstartedevent.Ensurethatthetargetprocessisconfiguredtouse.NETCore.Thismaybeexpectedifthetargetprocessdidnotrunon.NETCor

c# - 如何初始化 ConcurrentDictionary?错误 : "Cannot access private method ' Add' here"

我有一个静态类,我在其中使用字典作为查找表以在.NET类型和SQL类型之间进行映射。这是一个这样的字典的例子:privatestaticreadonlyDictionarySqlServerMap=newDictionary{{typeof(Boolean),"bit"},{typeof(Byte[]),"varbinary(max)"},{typeof(Double),"float"},{typeof(Byte),"tinyint"},{typeof(Int16),"smallint"},{typeof(Int32),"int"},{typeof(Int64),"bigint"},{

c# - 动态更改 Asp.Net Core 中的连接字符串

我想在Controller中更改sql连接字符串,而不是在ApplicationDbContext中。我正在使用Asp.NetCore和EntityFrameworkCore。例如:publicclassMyController:Controller{privatereadonlyApplicationDbContext_dbContextpublicMyController(ApplicationDbContextdbContext){_dbContext=dbContext;}privatevoidChangeConnectionString(){//So,whatshouldbe