C# IE(6&7)iFrame查询字符串参数在.NETMVC页面中设置不起作用,似乎已剥离,但在页面源代码中以Tact方式显示
我们正在使用.NETMVC,并且我们正在尝试(通过控制器)动态地设置iFrame的URL。这在FireFox和Chrome上运行良好,但在Ie上不起作用。在Ie上,只有第一个案例站点允许用户正确登录。v10和v9站点没有。所有站点都使用querystring参数登录。他们的来源看起来像这样(IE中不成功的来源)-没有明显的区别C# IE(6&7)iFrame查询字符串参数在.NETMVC页面中设置不起作用,似乎已剥离,但在页面源代码中以Tact方式显示,c#,asp.net-mvc,internet-explorer,iframe,C#,Asp.net Mvc,Internet Explorer,Iframe,我们正在使用.NETMVC,并且我们正在尝试(通过控制器)动态地设置iFrame的URL。这在FireFox和Chrome上运行良好,但在Ie上不起作用。在Ie上,只有第一个案例站点允许用户正确登录。v10和v9站点没有。所有站点都使用querystring参数登录。他们的来源看起来像这样(IE中不成功的来源)-没有明显的区别 此外,我们还尝试了整个IE7安全设置,允许导航到另一个域中的框架-这不是问题所在;它仍然不起作用。在IE6上也不起作用。与下面的屏幕截图中的结果相同 此外,Html编码
- 此外,我们还尝试了整个IE7安全设置,允许导航到另一个域中的框架-这不是问题所在;它仍然不起作用。在IE6上也不起作用。与下面的屏幕截图中的结果相同
- 此外,Html编码也没有起作用(未显示,但已尝试)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><title>
</title>
<style type="text/css">
td {
font-family: Arial;
font-size: small;
}
</style>
</head>
<body>
<form action="/Account/Navigate" method="post">
<table style="align: right; width: 100%;">
<tr>
<td align="right">
<input type="submit" name="butSubmit" value="WN" />
<input type="submit" name="butSubmit" value="MyDg" />
<input type="submit" name="butSubmit" value="V9" />
</td>
</tr>
</table>
<iframe id="displayFrame" src="http://my.totallyinsecuretopostthis.com/Login.aspx?&uname=sdavis&pword=04ab" style="width: 100%; height: 95%;"></iframe>
</form>
</body>
</html>
使用
HttpUtility.htmlAttributeNCode
对URL中的符号和进行编码:
ViewData["iFrameUrl"] = HttpUtility.HtmlAttributeEncode( string.Format( ... ) );
我建议在视图中呈现
标记时执行此操作,而不是在控制器中对其进行硬编码。这与查询字符串开头的“?&”无关
尝试一下:最终我找到了一个破解/解决方案-我从来没有让iFrame src=“mystring”工作过,但我确实创建了一个破解。B/c我们试图导航到的网站,我们自己的;所以我们在那个网站上创建了一个“镜像”页面。这几页看起来一模一样 1-我的iFrame原始页面,但我没有HREF,当你点击去我最初想要的地方 2-你点击了登录页面,并且登录了。。。但是我在这个登录页面中添加了querystring参数(我们也拥有这个站点),如果sso=true,并且您通过了身份验证,那么您将被重定向到 3-站点B上的页面,其iFrame与步骤1中的页面看起来相同 这是一个黑客,还有很多工作要做,但它“有效”,并且是我们最终能够创造的最好的用户体验
***感谢你们提供了答案的人,以及任何正在寻找答案的人。我非常感谢你的帮助 嗨,梅尔达德。我尝试在代码隐藏/控制器中以及在下面的示例所示的视图中对其进行编码-不走运。它仍然不起作用。好主意。我们有一个工作原理,它一定是以某种方式编码的。这也是我的想法——IE不喜欢这种语法,但这不是问题所在。最后我找到了一个破解/解决方案——我从来没有让iFrame src=“mystring”工作过,但我确实创建了一个破解。B/c我们试图导航到的网站,我们自己的;所以在那个网站上我们创建了一个“镜像”页面。
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<SingleSignOnUser>" %>
<%@ Import Namespace="Wingnut.Data.Model"%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
td {
font-family: Arial;
font-size: small;
}
</style>
</head>
<body>
<% using (Html.BeginForm("Navigate", "Account", FormMethod.Post)) { %>
<% TempData["username"] = Model.WingnutUserEmail; %>
<% TempData["password"] = Model.PasswordHash; %>
<table style="align: right; width: 100%;">
<tr>
<td align="right">
<!-- always display this, but when click, make sure you are authenticated; else, prompt for correct
wingnut password -->
<input type="submit" name="butSubmit" value="WN" />
<% if (Model.IsV10User()) { %>
<input type="submit" name="butSubmit" value="MyDg" />
<% } %>
<% if (Model.IsV9User()) { %>
<input type="submit" name="butSubmit" value="V9" />
<% } %>
</td>
</tr>
</table>
<% string url = ViewData["iFrameURL"].ToString(); %>
<% if (ViewData["iFrameURL"].ToString() != "popup") { %>
<iframe id="displayFrame" src="<%=ViewData["iFrameURL"]%>" style="width: 100%; height: 95%;"></iframe>
<% } %>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Navigate(string butSubmit) {
_service = new SSOUserService();
SingleSignOnUser wnUser = _service.GetValidUser(TempData["username"].ToString(), TempData["password"].ToString());
ViewData["iFrameURL"] = "http://www.usatoday.com";
try {
//if you are supposed to bypass the intersect page...
if (wnUser != null) {
switch (butSubmit) {
case "WN":
if (wnUser.IsWingnutUser())
ViewData["iFrameURL"] = string.Format("http://www.totallyinsecuretopostthis.com/users/{0}/login/{1}", wnUser.WingnutId, wnUser.WingnutToken);
else {
// do popup to capture this person's correct, but uncaptured, Wingnut password
// try to authenticate, if can, save, and proceed
// else, give error message / popup finally
ViewData["iFrameURL"] = "popup";
ViewData["popupText"] = "Oops. During the Totallyinsecuretopostthis's recent Single Sign On effort, we require that you enter your Totallyinsecuretopostthis" +
"password for us here one time only for authentication to SomePlace:";
}
break;
case "MyDg":
if (wnUser.IsV10User()) {
ViewData["iFrameURL"] =
string.Format(@"http://my.totallyinsecuretopostthisv10.com/Login.aspx?&uname={0}&pword={1}",
wnUser.V10UserCredentials.LoginName,
wnUser.V10UserCredentials.Password);
}
break;
case "V9":
if (wnUser.IsV9User()) {
ViewData["iFrameURL"] =
string.Format(
@"https://login.totallyinsecuretopostthisv9.com/clients/OtherPages/ExternalSignIn.aspx?UserName={0}&Password={1}",
wnUser.V9UserCredentials.LoginName, wnUser.V9UserCredentials.Password);
}
break;
}
}
}
catch (Exception ex) {
ModelState.AddModelError("Errors", ex.Message);
}
return View("Navigation", wnUser);
}
ViewData["iFrameUrl"] = HttpUtility.HtmlAttributeEncode( string.Format( ... ) );