2016-04-02 3 views
0

Я не могу понять, почему следующий код работает в VS 2012 и не работает в VS 2015:Request.Form не работает в VS 2015

getdata.html:

<!DOCTYPE html> 
    <html> 
    <head> 
     <title></title> 
     <meta charset="utf-8" /> 
    </head> 
    <body> 
     <form id="getcase" name="getcase" action="submit2crm.aspx"> 
      <input id="Text1" type="text" name="txt" /> 
      <input id="Submit1" type="submit" value="submit" /> 
     </form> 
    </body> 
    </html> 

submit2crm.aspx. cs:

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 

    public partial class w2c_submit2crm : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

      System.Text.StringBuilder displayValues = new System.Text.StringBuilder(); 
    System.Collections.Specialized.NameValueCollection postedValues = Request.Form; 
    String nextKey; 
    for (int i = 0; i < postedValues.AllKeys.Length; i++) 
    { 
     nextKey = postedValues.AllKeys[i]; 
     if (nextKey.Substring(0, 2) != "__") 
     { 
      displayValues.Append("<br>"); 
      displayValues.Append(nextKey); 
      displayValues.Append(" = "); 
      displayValues.Append(postedValues[i]); 
     } 
    } 
    Label1.Text = displayValues.ToString(); 
} 
} 

postedValues ​​все еще пусто после отправки формы. Любые идеи?

ответ

0

Обнаружил проблему самостоятельно: Это дружественная функция URL. Для того, чтобы Request.Form работать я изменил settings.AutoredirectMode Выкл в RouteConfig.cs файле конфигурации:

var settings = new FriendlyUrlSettings(); 
     settings.AutoRedirectMode = RedirectMode.Off; 
     routes.EnableFriendlyUrls(settings); 

RouteConfig.cs, расположенные в папке App_Start.

Эта статья поможет мне понять, в чем проблема: http://www.mikesdotnetting.com/article/293/request-form-is-empty-when-posting-to-aspx-page

Смежные вопросы