简体   繁体   English

如何从YSOD删除完整的文件路径?

[英]How to remove the full file path from YSOD?

In the YSOD below, the stacktrace (and the source file line) contain the full path to the source file. 在下面的YSOD中,stacktrace(和源文件行)包含源文件的完整路径。 Unfortunately, the full path to the source file name contains my user name, which is firstname.lastname . 不幸的是,源文件名的完整路径包含我的用户名,即firstname.lastname

I want to keep the YSOD, as well as the stack trace including the filename and line number (it's a demo and testing system), but the username should vanish from the sourcefile path. 我想保留YSOD以及包括文件名和行号(这是一个演示和测试系统)的堆栈跟踪,但是用户名应从源文件路径中消失。 Seeing the file's path is also OK, but the path should be truncated at the solution root directory. 看到文件的路径也可以,但是路径应在解决方案的根目录处被截断。

(without me having to copy-paste the solution every time to another path before publishing it...) (无需在每次发布前都将解决方案复制粘贴到另一个路径...)

Is there any way to accomplish this ? 有什么办法可以做到这一点?

Note: Custom error pages aren't an option. 注意:不能选择自定义错误页面。

在此处输入图片说明

Path is embedded in .pdb files, which are produced by the compiler. 路径嵌入在由编译器生成的.pdb文件中。 The only way to change this is to build your project in some other location, preferably somewhere near the build server. 更改此设置的唯一方法是在其他位置(最好在构建服务器附近)构建项目。

Never mind, I found it out myself. 没关系,我自己发现了。
Thanks to Anton Gogolev's statement that the path is in the pdb file, I realized it is possible. 感谢Anton Gogolev的声明,该路径位于pdb文件中,我意识到这是可能的。

One can do a binary search-and-replace on the pdb file, and replace the username with something else. 可以对pdb文件进行二进制搜索和替换,然后将用户名替换为其他名称。

I quickly tried using this: 我很快尝试使用此方法:
https://codereview.stackexchange.com/questions/3226/replace-sequence-of-strings-in-binary-file https://codereview.stackexchange.com/questions/3226/replace-sequence-of-strings-in-binary-file
and it worked (on 50% of the pdb files). 并且有效(对pdb文件的50%)。 So mind the crap, that code-snippet in the link seems to be buggy. 因此,请记住,该链接中的代码片段似乎有问题。

But the concept seems to work. 但是这个概念似乎行得通。

I now use this code: 我现在使用以下代码:

    public static void SizeUnsafeReplaceTextInFile(string strPath, string strTextToSearch, string strTextToReplace)
    {
        byte[] baBuffer = System.IO.File.ReadAllBytes(strPath);
        List<int> lsReplacePositions = new List<int>();

        System.Text.Encoding enc = System.Text.Encoding.UTF8;

        byte[] baSearchBytes = enc.GetBytes(strTextToSearch);
        byte[] baReplaceBytes = enc.GetBytes(strTextToReplace);

        var matches = SearchBytePattern(baSearchBytes, baBuffer, ref lsReplacePositions);

        if (matches != 0)
        {

            foreach (var iReplacePosition in lsReplacePositions)
            {

                for (int i = 0; i < baReplaceBytes.Length; ++i)
                {
                    baBuffer[iReplacePosition + i] = baReplaceBytes[i];
                } // Next i

            } // Next iReplacePosition

        } // End if (matches != 0)

        System.IO.File.WriteAllBytes(strPath, baBuffer);

        Array.Clear(baBuffer, 0, baBuffer.Length);
        Array.Clear(baSearchBytes, 0, baSearchBytes.Length);
        Array.Clear(baReplaceBytes, 0, baReplaceBytes.Length);

        baBuffer = null;
        baSearchBytes = null;
        baReplaceBytes = null;
    } // End Sub ReplaceTextInFile

Replace firstname.lastname with something that has equally many characters, for example "Poltergeist". 用具有多个相同字符的字符替换firstname.lastname ,例如“ Poltergeist”。

Now I only need to figure out how to run the binary search and replace as a post-build action. 现在,我只需要弄清楚如何运行二进制搜索并将其替换为生成后操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM