首页 \ 问答 \ 如何将ASP.NET Core UserSecrets部署到生产环境(How to deploy ASP.NET Core UserSecrets to production)

如何将ASP.NET Core UserSecrets部署到生产环境(How to deploy ASP.NET Core UserSecrets to production)

在开发过程中,在开发指南中关注了应用程序秘密安全存储,但在发布到另一台机器上进行质量检查,生产等时没有说明如何使用它。我认为它会插入它们在发布期间放入appsettings.json中,但它没有。 我最终不得不将SendGrid密钥和其他敏感信息直接放到appsettings.json中,这实际上破坏了应用程序机密的目的。

以最好的方式使用应用程序秘密还是有另一种方法来在我的配置中存储API密钥和SQL用户/密码?


I followed the Safe storage of app secrets during development guide over on the asp.net docs during development but it does not describe how to use it when publishing to another machine for QA, Production, etc. What I figured it would do was insert them into the appsettings.json during publish but it does not. I ended up having to place my SendGrid keys and other sensitive information directly into the appsettings.json which really defeats the purpose of the app secrets.

Is using app secrets the best way or is there another way to store API keys and SQL user/passwords in my configs?


原文:https://stackoverflow.com/questions/39668456
更新时间:2023-10-11 07:10

最满意答案

好的,错误说

-[__NSCFString setLinkID:]: unrecognized selector sent to instance 0x6bf37e0

请注意,您以某种方式将setLinkID:消息发送到__NSCFString的实例(基本上是NSString的私有子类)。

在您的代码中,您只发送setLinkID: to self。 因此,不知何故,您的解析器委托已被解除分配,并且取而代之的是已分配NSString的实例。

即使您使用ARC,您仍然必须了解对象所有权。 在这种情况下, NSXMLParser不会保留对其委托的引用 ,因为这很可能会创建保留周期。 如果查看标题或文档,您将看到该属性被定义为弱引用。

我认为正在发生的是你设置了解析器,你没有对主解析器委托的其他强引用,所以在解析开始后不久,它就被解除分配。 您需要浏览代码并确保对该主解析器委托有强引用。

如果你这样做,你会遇到问题:

NSXMLParser *parser = ...
[parser setDelegate:[[MyParserDelegate alloc] init]];
// delegate immediately deallocated, no strong references to it
if ([parser parse]) {
    MyParserDelegate *delegate = [parser delegate]; // nil or junk at this point

您应该像这样构建代码:

NSXMLParser *parser = ...
MyParserDelegate *topLevelDelegate = [[MyParserDelegate alloc] init];
[parser setDelegate:topLevelDelegate];
if ([parser parse]) {
    // pull data out of topLevelDelegate

如果您在专门的委托中使用交换模式,则topLevelDelegate需要维护对子委托的强引用。 如果您有从子级到父级的强引用,则无关紧要,因为子级本身只能从解析器本身访问,而解析器本身不会保留其委托。 您可能需要两种方式参考:从父母到孩子的强大; 从孩子到父母的弱势。 (通常,此模式将阻止保留周期。)

哦,回答你的标题问题:是的,ARC可以释放你正在使用的内存,如果它只能通过弱引用来访问它。 但是如果你正在使用它,你应该至少有一个强引用它。


OK, the error says

-[__NSCFString setLinkID:]: unrecognized selector sent to instance 0x6bf37e0

Note that you're somehow sending the setLinkID: message to an instance of __NSCFString (basically a private subclass of NSString).

In your code, you are only sending setLinkID: to self. So, somehow your parser delegate has been deallocated and, in its place, an instance of NSString has been allocated.

Even if you're using ARC, you still have to understand object ownership. In this case, the NSXMLParser does not retain a reference to its delegate, because that would very likely create a retain cycle. If you look in the headers or the documentation you will see that the property is defined as a weak reference.

What I think is happening is that you set up the parser, you have no other strong reference to the main parser delegate, so shortly after parsing begins, it is deallocated. You need to go through your code and make sure you have a strong reference to that main parser delegate.

You will have problems if you do this:

NSXMLParser *parser = ...
[parser setDelegate:[[MyParserDelegate alloc] init]];
// delegate immediately deallocated, no strong references to it
if ([parser parse]) {
    MyParserDelegate *delegate = [parser delegate]; // nil or junk at this point

You should structure your code like this:

NSXMLParser *parser = ...
MyParserDelegate *topLevelDelegate = [[MyParserDelegate alloc] init];
[parser setDelegate:topLevelDelegate];
if ([parser parse]) {
    // pull data out of topLevelDelegate

If you use the pattern of swapping in specialized delegates, the topLevelDelegate needs to maintain a strong reference to the child delegates. If you have a strong reference from the child to the parent, it won't matter, because the child itself will only be reachable from the parser itself, which doesn't retain its delegate. You will probably need a reference both ways: strong from parent to child; weak from child to parent. (In general, this pattern will prevent retain cycles.)

Oh, to answer your title question: Yes, it's possible for ARC to release memory you are using, if it is only reachable by weak references to it. But if you're using it, you should have at least one strong reference to it.

相关问答

更多
  • 好的,错误说 -[__NSCFString setLinkID:]: unrecognized selector sent to instance 0x6bf37e0 请注意,您以某种方式将setLinkID:消息发送到__NSCFString的实例(基本上是NSString的私有子类)。 在您的代码中,您只发送setLinkID: to self。 因此,不知何故,您的解析器委托已被解除分配,并且取而代之的是已分配NSString的实例。 即使您使用ARC,您仍然必须了解对象所有权。 在这种情况下, N ...
  • GLKit是一个Objective-C框架。 每当您处理Objective-C对象时,ARC都会管理它们的内存。 所以要回答你的问题,不,你不需要手动释放内存,只要你只创建Objective-C对象(如GLKViewController , GLKView ,...)。 GLKit is an Objective-C framework. Whenever you are dealing with Objective-C objects, ARC will manage their memory. So t ...
  • Q)视图控制器被按下并弹出8-10次时会出现问题。 当弹出视图控制器时,我在AVAudioPlayer上调用stop并将所有相关对象(包括AVAudioPlayer实例)返回到nil。 A)添加一个dealloc方法并记录dealloc,所以你知道什么都没有保留那些,然后在控制台中查找这些: - (void)dealloc { NSLog(@"MySpecialViewController getting dealloced!"); } 如果你没有看到这些东西保留了这个对象 - 可能是一个委托。 问: ...
  • 我已经解决了将__weak或__unsafe_unretained放在引用父类的实例变量之前,如果该父类具有对子项的引用。 使用任何一种都意味着父对象的引用计数不会增加。 如果要在访问变量时抛出异常但对象已释放,请使用__unsafe_unretained。 如果不需要异常,请使用__weak,释放对象时变量将变为nil。 @implementation SomeClass{ NSString *someVariable; ChildClass *childVariable; __u ...
  • 页面的UIImage全部保存在一个数组中。 当您将UIImageView的属性设置为nil时, UIImage不会被释放,因为该数组仍然持有对它们的引用。 至于记忆力的增长,它可能是被分配的其他东西。 我建议您使用Instrument的对象分配工具来查看滚动时的确切增长情况。 The UIImage's for the pages are all held in an array. The UIImage's are not being deallocated when you set the UIImag ...
  • 有一些方法可以说,通过在不需要某些东西时将它们的属性设置为nil来“优化”你的对象 - 所以当你不能再写一个dealloc方法时,你可以做self.object = nil (当相关的时候)最终在非ARC世界中为“保留”(即strong )属性做类似的事情: - (void)setObject:(id)newObject { [object release]; // send release message to current object object = newObject; // set ...
  • 不。目前,ARC不处理内存管理,除了Obj-C对象(CGPDF的东西不是)。 No. ARC does not currently handle the memory management for anything except Obj-C objects (which CGPDF things aren't).
  • 如果您的图像很大,请看这个问题: 在UIScrollView中使用相当大的图像解决UIImageViews使用的内存问题 总结一下:使用nib文件时,所有已分配的图像都是使用加载的 [UIImage imageNamed] 已知会导致大量内存分配的方法,因为它总是缓存图像。 尝试将图像分配给代码中的视图 [UIImage imageWithContentsOfFile:path]; 方法(在上述问题的答案中描述)。 If Your images are big please see this quest ...
  • 您需要了解内存管理的基础知识。 在ARC中,只要对象至少有一个强引用,对象就会保存在内存中。 只要不再有任何对象的强引用,它就可能被释放。 NSArray(或NSMutableArray)对添加到它的任何对象保持强大的引用。 如果你从一个可变数组中移除一个对象(例如使用removeObjectAtIndex: , removeObjectAtIndex:这个数组会释放它的强引用。 你的代码从数组中获取对象,然后将局部变量设置为零,这绝对不会浪费时间: for(short i=0; i<10; i++){ ...
  • ARC没有垃圾收集,所以没有任何可以调用的东西。 如果您控制对象的范围和所有权,则ARC将为您提供内存使用。 除了给引用赋予'nil'或者让引用超出范围之外,唯一的另外一个考虑是你是否有一些额外的对象引用(比如把它放到一个NSArray中),它有它自己的需要保留这个对象。 There is no garbage collection with ARC, so there is nothing to call. If you control the scope and ownership of your ob ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。