1
是否可以使用C#HTML Agility Pack將變量插入選定節點?使用Html Agility Pack C將變量注入html輸入標記值#
我已經創建了我的HTML表單,加載它,並選擇我想要的輸入節點,現在我想在價值領域注入SAML響應
這裏是一個位碼的我有,首先在HTML文檔:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body runat="server" id="bodySSO">
<form id="frmSSO" runat="server" enableviewstate="False">
<div style="display:none" >
<input id="SAMLResponse" name="SAMLResponse" type="text" runat="server" enableviewstate="False" value=""/>
<input id="Query" name="Query" type="text" runat="server" enableviewstate="False" value=""/>
</div>
</form>
</body>
</html>
,這裏是它加載的HTML文件,並選擇我想要的節點的功能:
public static string GetHTMLForm(SamlAssertion samlAssertion)
{
HtmlAgilityPack.HtmlDocument HTMLSamlDocument = new HtmlAgilityPack.HtmlDocument();
HTMLSamlDocument.Load(@"C:\HTMLSamlForm.html");
HtmlNode node = HTMLSamlDocument.DocumentNode.SelectNodes("//input[@id='SAMLResponse']").First();
//Code that will allow me to inject into the value field my SAML Response
}
編輯:
好了,所以我已經實現了SAML響應數據包注入HTML的輸入標籤的這個「價值」字段:
HtmlAgilityPack.HtmlDocument HtmlDoc = new HtmlAgilityPack.HtmlDocument();
String SamlInjectedPath = "C:\\SamlInjected.txt";
HtmlDoc.Load(@"C:\HTMLSamlForm.txt");
var SAMLResposeNode = HtmlDoc.DocumentNode.SelectSingleNode("//input[@id='SAMLResponse']").ToString();
SAMLResposeNode = "<input id='SAMLResponse' name='SAMLResponse' type='text' runat='server' enableviewstate='False' value='" + samlAssertion + "'/>";
現在我只需要能夠補充說,注入標籤回原始的HTML文檔
我想可能有一些有用的東西在這個問題上 http://stackoverflow.com/questions/9520932/how-do-i-use-html-agility-pack-to-edit -an-HTML的代碼段 – Pete