2012-09-04 30 views
0

在下面的YSOD中,stacktrace(和源文件行)包含源文件的完整路徑。不幸的是,源文件名的完整路徑包含我的用戶名,即firstname.lastname如何從YSOD中刪除完整的文件路徑?

我想保留YSOD以及堆棧跟蹤,包括文件名和行號(它是一個演示和測試系統),但用戶名應該從源文件路徑中消失。查看文件的路徑也可以,但路徑應該在解決方案根目錄處截斷。

(沒有我不得不到其他路徑每次複製粘貼的解決方案發布之前...)

有沒有辦法做到這一點?

注意:自定義錯誤頁面不是一個選項。

enter image description here

+0

我不相信你可以修改它。恐怕你唯一的選擇就是將你的項目和文件移到包含你的名字的文件夾之外。例如,將所有內容放在'D:\ Projects \ CR-Library'中,一旦生成,調試信息將使用該路徑。 – Omar

回答

0

沒關係,我自己找到了。
感謝Anton Gogolev聲明路徑在pdb文件中,我意識到這是可能的。

可以在pdb文件上進行二分查找和替換,並用其他名稱替換用戶名。

我趕緊用這個嘗試:
https://codereview.stackexchange.com/questions/3226/replace-sequence-of-strings-in-binary-file
和它的工作(在PDB文件的50%)。 因此,記住廢話,鏈接中的代碼片段似乎是越野車。

但這個概念似乎工作。

我現在使用此代碼:

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 

更換firstname.lastname的東西,同樣具有許多字符,例如「鬼驅人」。

現在我只需要弄清楚如何運行二分查找並替換爲構建後的操作。

1

路徑被嵌入在.pdb文件,這是由編譯器產生的。改變這種情況的唯一方法是在其他位置構建項目,最好是在構建服務器附近。

+0

是的,這正是我不想聽的那種答案;) –