Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用html Agility Pack C将变量注入html输入标记值#_C#_Html_Html Agility Pack_Saml - Fatal编程技术网

C# 使用html Agility Pack C将变量注入html输入标记值#

C# 使用html Agility Pack C将变量注入html输入标记值#,c#,html,html-agility-pack,saml,C#,Html,Html Agility Pack,Saml,是否可以使用C#HTML Agility Pack将变量插入所选节点 我已经创建了我的HTML表单,加载了它,并选择了我想要的输入节点,现在我想在value字段中注入一个SAML响应 下面是我的一些代码,首先是HTML文档: <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> &

是否可以使用C#HTML Agility Pack将变量插入所选节点

我已经创建了我的HTML表单,加载了它,并选择了我想要的输入节点,现在我想在value字段中注入一个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>
编辑:

好的,我已经实现了将SAML响应包注入html输入标记的“value”字段,如下所示:

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 + "'/>";
HtmlAgilityPack.HtmlDocument HtmlDoc=新的HtmlAgilityPack.HtmlDocument();
字符串SamlInjectedPath=“C:\\SamlInjected.txt”;
Load(@“C:\HTMLSamlForm.txt”);
var SAMLResposeNode=HtmlDoc.DocumentNode.SelectSingleNode(“//输入[@id='SAMLResponse']”)。ToString();
SAMLResposeNode=“”;

现在,我只需要能够将注入的标记添加回原始HTML文档中

好的,我使用以下方法解决了这个问题:

HtmlAgilityPack.HtmlDocument HtmlDoc = new HtmlAgilityPack.HtmlDocument();
HtmlDoc.Load(@"C:\HTMLSamlForm.html");
var SamlNode = HtmlNode.CreateNode("<input id='SAMLResponse' name='SAMLResponse' type='text' runat='server' enableviewstate='False' value='" + samlAssertion + "'/>");
foreach (HtmlNode node in HtmlDoc.DocumentNode.SelectNodes("//input[@id='SAMLResponse']"))
{
    string value = node.Attributes.Contains("value") ? node.Attributes["value"].Value : "&nbsp;";
    node.ParentNode.ReplaceChild(SamlNode, node);
}

好的,我已经用以下方法解决了这个问题:

HtmlAgilityPack.HtmlDocument HtmlDoc = new HtmlAgilityPack.HtmlDocument();
HtmlDoc.Load(@"C:\HTMLSamlForm.html");
var SamlNode = HtmlNode.CreateNode("<input id='SAMLResponse' name='SAMLResponse' type='text' runat='server' enableviewstate='False' value='" + samlAssertion + "'/>");
foreach (HtmlNode node in HtmlDoc.DocumentNode.SelectNodes("//input[@id='SAMLResponse']"))
{
    string value = node.Attributes.Contains("value") ? node.Attributes["value"].Value : "&nbsp;";
    node.ParentNode.ReplaceChild(SamlNode, node);
}

我在想这个问题中可能有一些有用的东西我在想这个问题中可能有一些有用的东西
System.IO.File.WriteAllText(@"C:\SamlInjected.txt", HtmlDoc.DocumentNode.OuterHtml);