C# 在Windows 2012 Server上迁移到IIS8-远程Post现在显示一个空白页
我最近将一个运行在Windows 2003服务器IIS6上的V2.20 nopCommerce网站移动到运行在Windows 2012服务器上的IIS8,现在当对WorldPay模块执行远程post时,我看到的只是一个空白的白色屏幕 我有一种感觉,这不仅限于WorldPay模块或nopCommerce,更像是一个MVC问题,其代码是在ASP.NET4.5上运行的ASP.Net早期版本中开发的 那么,是否有人有任何想法或解决方案来解释为什么远程post无法工作,请参见下面的远程post示例代码,当它被写入HTTP上下文时,表单似乎不会触发body onload事件C# 在Windows 2012 Server上迁移到IIS8-远程Post现在显示一个空白页,c#,asp.net,asp.net-mvc,nopcommerce,C#,Asp.net,Asp.net Mvc,Nopcommerce,我最近将一个运行在Windows 2003服务器IIS6上的V2.20 nopCommerce网站移动到运行在Windows 2012服务器上的IIS8,现在当对WorldPay模块执行远程post时,我看到的只是一个空白的白色屏幕 我有一种感觉,这不仅限于WorldPay模块或nopCommerce,更像是一个MVC问题,其代码是在ASP.NET4.5上运行的ASP.Net早期版本中开发的 那么,是否有人有任何想法或解决方案来解释为什么远程post无法工作,请参见下面的远程post示例代码,当
using System.Collections.Specialized;
using System.Web;
using Nop.Core;
using Nop.Core.Infrastructure;
namespace Nop.Web.Framework
{
/// <summary>
/// Represents a RemotePost helper class
/// </summary>
public partial class RemotePost
{
private readonly HttpContextBase _httpContext;
private readonly IWebHelper _webHelper;
private readonly NameValueCollection _inputValues;
/// <summary>
/// Gets or sets a remote URL
/// </summary>
public string Url { get; set; }
/// <summary>
/// Gets or sets a method
/// </summary>
public string Method { get; set; }
/// <summary>
/// Gets or sets a form name
/// </summary>
public string FormName { get; set; }
/// <summary>
/// Gets or sets a form character-sets the server can handle for form-data.
/// </summary>
public string AcceptCharset { get; set; }
/// <summary>
/// A value indicating whether we should create a new "input" HTML element for each value (in case if there are more than one) for the same "name" attributes.
/// </summary>
public bool NewInputForEachValue { get; set; }
public NameValueCollection Params
{
get
{
return _inputValues;
}
}
/// <summary>
/// Creates a new instance of the RemotePost class
/// </summary>
public RemotePost()
: this(EngineContext.Current.Resolve<HttpContextBase>(), EngineContext.Current.Resolve<IWebHelper>())
{
}
/// <summary>
/// Creates a new instance of the RemotePost class
/// </summary>
/// <param name="httpContext">HTTP Context</param>
/// <param name="webHelper">Web helper</param>
public RemotePost(HttpContextBase httpContext, IWebHelper webHelper)
{
this._inputValues = new NameValueCollection();
this.Url = "http://www.someurl.com";
this.Method = "post";
this.FormName = "formName";
this._httpContext = httpContext;
this._webHelper = webHelper;
}
/// <summary>
/// Adds the specified key and value to the dictionary (to be posted).
/// </summary>
/// <param name="name">The key of the element to add</param>
/// <param name="value">The value of the element to add.</param>
public void Add(string name, string value)
{
_inputValues.Add(name, value);
}
/// <summary>
/// Post
/// </summary>
public void Post()
{
_httpContext.Response.Clear();
_httpContext.Response.Write("<html><head>");
_httpContext.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
if (!string.IsNullOrEmpty(AcceptCharset))
{
//AcceptCharset specified
_httpContext.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" accept-charset=\"{3}\">", FormName, Method, Url, AcceptCharset));
}
else
{
//no AcceptCharset specified
_httpContext.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
}
if (NewInputForEachValue)
{
foreach (string key in _inputValues.Keys)
{
string[] values = _inputValues.GetValues(key);
if (values != null)
{
foreach (string value in values)
{
_httpContext.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", HttpUtility.HtmlEncode(key), HttpUtility.HtmlEncode(value)));
}
}
}
}
else
{
for (int i = 0; i < _inputValues.Keys.Count; i++)
_httpContext.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", HttpUtility.HtmlEncode(_inputValues.Keys[i]), HttpUtility.HtmlEncode(_inputValues[_inputValues.Keys[i]])));
}
_httpContext.Response.Write("</form>");
_httpContext.Response.Write("</body></html>");
_httpContext.Response.End();
//store a value indicating whether POST has been done
_webHelper.IsPostBeingDone = true;
}
}
}
使用System.Collections.Specialized;
使用System.Web;
使用Nop.Core;
使用Nop.Core.Infrastructure;
命名空间Nop.Web.Framework
{
///
///表示RemotePost帮助程序类
///
公共部分类RemotePost
{
私有只读HttpContextBase_httpContext;
私有只读IWebHelper\u webHelper;
私有只读NameValueCollection\u inputValues;
///
///获取或设置远程URL
///
公共字符串Url{get;set;}
///
///获取或设置一个方法
///
公共字符串方法{get;set;}
///
///获取或设置窗体名称
///
公共字符串FormName{get;set;}
///
///获取或设置服务器可以为表单数据处理的表单字符集。
///
公共字符串AcceptCharset{get;set;}
///
///一个值,指示是否应该为同一“name”属性的每个值(如果有多个值)创建一个新的“input”HTML元素。
///
公共bool NewInputForEachValue{get;set;}
public NameValueCollection参数
{
得到
{
返回_输入值;
}
}
///
///创建RemotePost类的新实例
///
公共远程邮政()
:这是(EngineContext.Current.Resolve(),EngineContext.Current.Resolve())
{
}
///
///创建RemotePost类的新实例
///
///HTTP上下文
///网络助手
公共RemotePost(HttpContextBase httpContext,IWebHelper webHelper)
{
这是._inputValues=new NameValueCollection();
此Url=”http://www.someurl.com";
方法=“post”;
this.FormName=“FormName”;
这是.\u httpContext=httpContext;
这个。_webHelper=webHelper;
}
///
///将指定的键和值添加到字典(要发布)。
///
///要添加的元素的键
///要添加的元素的值。
公共void添加(字符串名称、字符串值)
{
_输入值。添加(名称、值);
}
///
///职位
///
公共空缺职位()
{
_httpContext.Response.Clear();
_httpContext.Response.Write(“”);
_httpContext.Response.Write(string.Format(“,FormName));
如果(!string.IsNullOrEmpty(AcceptCharset))
{
//指定的接受字符集
_httpContext.Response.Write(string.Format(“,FormName,方法,Url,AcceptCharset));
}
其他的
{
//未指定AcceptCharset
_httpContext.Response.Write(string.Format(“,FormName,Method,Url));
}
if(NewInputForEachValue)
{
foreach(字符串键输入_inputValues.Keys)
{
字符串[]值=_inputValues.GetValues(键);
如果(值!=null)
{
foreach(值中的字符串值)
{
_httpContext.Response.Write(字符串.Format(“,HttpUtility.HtmlEncode(键),HttpUtility.HtmlEncode(值));
}
}
}
}
其他的
{
对于(int i=0;i<\u inputValues.Keys.Count;i++)
_httpContext.Response.Write(string.Format(“,HttpUtility.HtmlEncode(_inputValues.Keys[i]),HttpUtility.HtmlEncode(_inputValues[_inputValues.Keys[i]]);
}
_httpContext.Response.Write(“”);
_httpContext.Response.Write(“”);
_httpContext.Response.End();
//存储一个值,该值指示是否已完成POST
_webHelper.IsPostBeingDone=true;
}
}
}
经过多次搜索,我发现了以下帖子:
结果表明Response.Close()的工作原理与预期不符,有时可能会丢失数据,因此建议使用以下代码行:
HttpContext.Current.ApplicationInstance.CompleteRequest()强>
我试了一下,RemotePost马上又开始工作了。下面是另一篇关于Response.Close()为什么不能始终按预期工作的有用文章
经过多次搜索,我发现了以下帖子: 结果表明Response.Close()的工作原理与预期不符,有时可能会丢失数据,因此建议使用以下代码行: HttpContext.Current.ApplicationInstance.CompleteRequest()强> 我试了一下,RemotePost马上又开始工作了。下面是另一篇关于Response.Close()为什么不能始终按预期工作的有用文章