visual-studio 调试 IIS 时关闭 Visual Studio 附加安全警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1414769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:00:17  来源:igfitidea点击:

Turn off Visual Studio Attach security warning when debugging IIS

visual-studio-2010visual-studiovisual-studio-2008iisiis-7

提问by roundcrisis

When using Visual Studio 2008 or 2010, every time you attach to IIS w3wp.exe you get an Attach Security Warning,

使用 Visual Studio 2008 或 2010 时,每次附加到 IIS w3wp.exe 时都会收到附加安全警告,

How do you turn this of?

你怎么转这个?

It would be cool to know also, how to keep it attached for linger, as this seems to time out after a while.

也很高兴知道如何保持它的附着以留连忘返,因为这似乎会在一段时间后超时。

Btw: I Added this as a comment to the answer below, the first thing I did was try the msdn article http://msdn.microsoft.com/en-us/library/ms241736.aspxbut that doesn't work.

顺便说一句:我将此作为评论添加到下面的答案中,我做的第一件事是尝试 msdn 文章 http://msdn.microsoft.com/en-us/library/ms241736.aspx但这不起作用。

回答by Wiebe Tijsma

Also found in the article mentioned by Tzury, but to sum up the answers in this thread:

也可以在 Tzury 提到的文章中找到,但总结一下这个线程中的答案:

make sure Visual Studio is not running when changing the registry key or it will be overwritten on exit with the old value

确保更改注册表项时 Visual Studio 未运行,否则将在退出时用旧值覆盖

Change (or create) the following registry key to 1:

将以下注册表项更改(或创建)为1

Visual Studio 2008HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Debugger\DisableAttachSecurityWarning

视觉工作室 2008HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Debugger\DisableAttachSecurityWarning

Visual Studio 2010HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Debugger\DisableAttachSecurityWarning

视觉工作室 2010HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Debugger\DisableAttachSecurityWarning

Visual Studio 2012HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\Debugger\DisableAttachSecurityWarning

视觉工作室 2012HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\Debugger\DisableAttachSecurityWarning

Visual Studio 2013HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\Debugger\DisableAttachSecurityWarning

视觉工作室 2013HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\Debugger\DisableAttachSecurityWarning

Visual Studio 2015HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\Debugger\DisableAttachSecurityWarning

视觉工作室 2015HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\Debugger\DisableAttachSecurityWarning

For VS2015, you might need to create the Registry Key referenced above.

对于 VS2015,您可能需要创建上面引用的注册表项。

  1. Make sure Visual Studio is not running, and open the Registry Editor.
  2. Navigate to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\Debugger, right-click and create a new DWORD:
    • Name: DisableAttachSecurityWarning
    • Value: 1.
  1. 确保 Visual Studio 未运行,然后打开注册表编辑器。
  2. 导航到 HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\Debugger,右键单击并创建一个新的DWORD
    • 名称: DisableAttachSecurityWarning
    • 价值:1

Update:If you don't want to open up regedit, save this gistas a *.reg file and run it (imports the keys for all VS versions lower than VS2017).

更新:如果你不想打开 regedit,把这个gist保存为 *.reg 文件并运行它(导入所有低于 VS2017 的 VS 版本的密钥)。

Visual Studio 2017

视觉工作室 2017

The configuration is saved in a private registry location, see this answer: https://stackoverflow.com/a/41122603/67910

配置保存在私有注册表位置,请参阅此答案:https: //stackoverflow.com/a/41122603/67910

For VS 2017, save this gistas a *.ps1 file and run it as admin, or copy and paste the following code in a ps1 file:

对于VS 2017,将此gist保存为 *.ps1 文件并以管理员身份运行,或将以下代码复制并粘贴到 ps1 文件中:

#IMPORTANT: Must be run as admin

dir $env:LOCALAPPDATA\Microsoft\VisualStudio.* | % {
    #https://stackoverflow.com/a/41122603
    New-PSDrive HKU Registry HKEY_USERS

    reg load 'HKU\VS2017PrivateRegistry\' $_\privateregistry.bin

    $BasePath='HKU:\VS2017PrivateRegistry\Software\Microsoft\VisualStudio'

    $keysResult=dir $BasePath
    $keysResult | ? {$_.Name -match '\\d+\.\d+_[^_]+$'} | % {
        $keyName = $_.Name -replace 'HKEY_USERS','HKU:'
        New-ItemProperty -Path $keyName\Debugger -Name DisableAttachSecurityWarning -Value 1
    }
    $keysResult.Handle.Close()    

    [gc]::collect()

    reg unload 'HKU\VS2017PrivateRegistry'

    Remove-PSDrive HKU
}

回答by Chris R. Donnelly

The registry setting does work; however, you have to make sure you set it in the 32-bit registry sandbox for VS2005/2008 by either using the 32-bit regedit.exe in %windir%\SysWOW64\or adding it under HKLM\Software\Wow6432Node\.... I created a .reg script that simply adds it to both:

注册表设置确实有效;但是,您必须确保在 VS2005/2008 的 32 位注册表沙箱中设置它,方法是%windir%\SysWOW64\HKLM\Software\Wow6432Node\.... 我创建了一个 .reg 脚本,它只是将它添加到两者中:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio.0\Debugger]
"DisableAttachSecurityWarning"=dword:00000001

[HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\VisualStudio.0\Debugger]
"DisableAttachSecurityWarning"=dword:00000001

Just change the version to 8.0 for 2005, 10.0 for 2010, etc.

只需将版本更改为 2005 的 8.0、2010 的 10.0 等。

NOTE: regedit on Windows 7 seems to want .reg files saved as UTF16-LE, so if you save it to a .reg file, be aware you need to do that.

注意:Windows 7 上的 regedit 似乎希望将 .reg 文件保存为 UTF16-LE,因此如果您将其保存为 .reg 文件,请注意您需要这样做。

回答by Eric Villemure

I was able to make it Work on Windows 7. I have first changed the registry value with VS2008 still opened. I then closed it and refreshed the registry editor and noticed that the value was reset to 0. I then changed it back to 1 and started VS2008. It now works fine. I have tried to close VS2008 and open it back and the registry value stays 1. Thanks for your help

我能够让它在 Windows 7 上工作。我首先在 VS2008 仍然打开的情况下更改了注册表值。然后我关闭它并刷新注册表编辑器,发现该值被重置为 0。然后我将它改回 1 并启动 VS2008。它现在工作正常。我尝试关闭 VS2008 并重新打开它,但注册表值保持为 1。感谢您的帮助

回答by Martin Hollingsworth

The other answers in this post contain the right information but I had problems getting it to work so this is an attempt at make the answer very explicit. These instructions worked for Visual Studio 2010 running on Windows 7 Ultimate 64-Bit.

这篇文章中的其他答案包含正确的信息,但我在让它工作时遇到了问题,所以这是尝试使答案非常明确。这些说明适用于在 Windows 7 Ultimate 64 位上运行的 Visual Studio 2010。

  • Ensure that no instances of Visual Studio are running (Use task manager to check for devenv.exe)
  • Add the DWORD DisableAttachSecurityWarningregistry value to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\X.X\Debuggerand set the value to be 1. For Visual Studio 2008 replace X.X with 9.0, for 2010 use 10.0
  • 确保没有运行 Visual Studio 实例(使用任务管理器检查devenv.exe
  • 将 DWORD DisableAttachSecurityWarning注册表值添加到HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\XX\Debugger并将值设置为1。对于 Visual Studio 2008 将 XX 替换为9.0,对于 2010 使用10.0

The reason why I struggled to get this working was that I was trying this using HKEY_LOCAL_MACHINE instead of HKEY_CURRENT_USER. I had to resort to using Process Monitorand a bit of filtering on devenv to identify my mistake. I suspect the HKLM value only has any affect if it gets set before you open Visual Studio for the first time.

我努力让它工作的原因是我尝试使用 HKEY_LOCAL_MACHINE 而不是 HKEY_CURRENT_USER。我不得不求助于使用Process Monitor和对 devenv 的一些过滤来识别我的错误。我怀疑 HKLM 值只有在您第一次打开 Visual Studio 之前设置时才会有任何影响。

Any open instances of Visual Studio will overwrite your changes when they are closed and only new instances would pick up the setting in any case.

Visual Studio 的任何打开实例在关闭时都将覆盖您的更改,并且在任何情况下只有新实例会选择设置。

The use of the Wow6432Noderegistry seems to be unnecessary as far as I can tell. The following Powershell commands will apply the steps for Visual Studio 2010.

据我所知,使用Wow6432Node注册表似乎没有必要。以下 Powershell 命令将应用 Visual Studio 2010 的步骤。

Get-Process -Name devenv* | ForEach-Object { Stop-Process $_.Id }
New-ItemProperty -Path 'HKCU:\Software\Microsoft\VisualStudio.0\Debugger' -Name 'DisableAttachSecurityWarning' -Value 1 -PropertyType 'DWORD' -Force

回答by Tóth Zoltán

You can change the iis AppPool identity to your actual windows user, if it is a local machine.

如果是本地机器,您可以将 iis AppPool 身份更改为您的实际 Windows 用户。

回答by Tzury Bar Yochay

your answer is available at http://msdn.microsoft.com/en-us/library/ms241736.aspx

您的答案可在http://msdn.microsoft.com/en-us/library/ms241736.aspx 上找到

If you are debugging a legitimate scenario that causes this warning to appear, and want to suppress it, there is a registry setting that allows you to do this. Remember to re-enable the warning after you are done with the scenario.

如果您正在调试导致出现此警告的合法场景,并希望取消它,则可以使用注册表设置来执行此操作。请记住在完成场景后重新启用警告。

回答by Alexei

This is not a direct answer to the question, but it circumvents the security message and also provides a faster way to attach to a previously attached process:

这不是问题的直接答案,但它绕过了安全消息,还提供了一种更快的方式来附加到先前附加的进程:

  • install Reattach extension
  • attach using Reattach and the message is bypassed
  • re-attaching (Ctrl-R + Ctrl-[1-5]) to a previous process has the same benefit
  • 安装重新附加扩展
  • 使用 Reattach 附加并绕过消息
  • 将 (Ctrl-R + Ctrl-[1-5]) 重新附加到先前的进程具有相同的好处

回答by SliverNinja - MSFT

Powershellvariant...replace $vsversionwith the version you want to apply it to.

Powershell变体...替换$vsversion为您要应用它的版本。

Note: Save your work before running this. All running VS instances will be stopped. If you don't end open VS instances - the value will not be retained.

注意:在运行之前保存您的工作。所有正在运行的 VS 实例都将停止。如果您不结束打开的 VS 实例 - 该值将不会保留。

$vsversion = "12.0" # VS 2013 (optionally 11, 10, 9, etc.)
kill -name devenv # end any existing VS instances (required for persisting config change)
Get-ItemProperty -Path "HKCU:\Software\Microsoft\VisualStudio$vsversion\Debugger" -Name DisableAttachSecurityWarning -ErrorAction SilentlyContinue # query value (ignore if not exists)
Set-ItemProperty -Path "HKCU:\Software\Microsoft\VisualStudio$vsversion\Debugger" -Name DisableAttachSecurityWarning -Value 1 # assign value

回答by Shawn Cicoria

so, the only thing that would work for me with Visual Studio 2010 on x64/Win7 is to update both nodes, including the Wow6432Node.

因此,在 x64/Win7 上使用 Visual Studio 2010 唯一对我有用的是更新两个节点,包括 Wow6432Node。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio.0\Debugger]
"DisableAttachSecurityWarning"=dword:00000001

[HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\VisualStudio.0\Debugger]
"DisableAttachSecurityWarning"=dword:00000001

回答by Marc Gravell

A Visual Studio extension is available for VS2015 and VS2017: "Attach To All The Things":

Visual Studio 扩展可用于 VS2015 和 VS2017:“Attach To All The Things”

enter image description here

在此处输入图片说明

You can bind "Attach To IIS" to whatever key chord you like using the usual process.

您可以使用通常的过程将“附加到 IIS”绑定到您喜欢的任何键和弦。