【问题标题】:Migration to IIS8 on Windows 2012 Server - Remote Post now shows a blank page在 Windows 2012 Server 上迁移到 IIS8 - Remote Post 现在显示空白页
【发布时间】:2015-06-24 07:22:15
【问题描述】:

我最近将一个在 Windows 2003 服务器上的 IIS6 上运行的 V2.20 nopCommerce 网站移动到在 Windows 2012 服务器上运行的 IIS8,现在当为 WorldPay 模块执行远程发布时,我看到的只是一个空白的白色屏幕?

我感觉这不仅限于 WorldPay 模块或确实 nopCommerce,而且更多的是 MVC 问题,代码是在 ASP.Net 4.5 上运行的早期版本的 ASP.Net 中开发的。

那么有没有人对为什么远程帖子不起作用有任何想法或解决方案,请参阅下面的远程帖子示例代码,将其写入 HTTP 上下文时的表单似乎不会触发正文 onload事件。

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;
    }
}
}

【问题讨论】:

    标签: c# asp.net asp.net-mvc nopcommerce


    【解决方案1】:

    经过大量搜索,我发现了以下帖子:

    ASP.NET MVC 3 - Replacing HttpContext Response Not Working

    事实证明 Response.Close() 并没有按预期工作,有时会丢失数据,因此建议改用以下代码行:

    HttpContext.Current.ApplicationInstance.CompleteRequest();

    我尝试了这个,RemotePost 立即重新开始工作。下面是另一篇关于为什么 Response.Close() 并不总是按预期工作的有用文章。

    http://blogs.msdn.com/b/aspnetue/archive/2010/05/25/response-end-response-close-and-how-customer-feedback-helps-us-improve-msdn-documentation.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      • 2020-08-26
      • 2014-08-06
      相关资源
      最近更新 更多