
ASP.NET WebフォームにPOSTしているはずなのに、そのWebフォームのPage_LoadメソッドではRequest.HttpMethodがGETになります。
Web.config 等の設定も関係しているでしょうか?
POST元のソースは下記の通りです
###該当のソースコード
遷移元
CS.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> First Name: </td> <td> <asp:TextBox ID="txtFirstName" runat="server" /> </td> </tr> <tr> <td> Last Name: </td> <td> <asp:TextBox ID="txtLastName" runat="server" /> </td> </tr> <tr> <td> </td> <td> <asp:Button ID="btnPost" runat="server" Text="ポスト" OnClick="PostData" /> </td> </tr> </table> </div> </form> </body> </html>
CS.aspx.cs
protected void PostData(object sender, EventArgs e) { NameValueCollection collections = new NameValueCollection(); collections.Add("FirstName", txtFirstName.Text.Trim()); collections.Add("LastName", txtLastName.Text.Trim()); string remoteUrl = "http://localhost:58441/Page2_CS.aspx"; string html = "<html><head>"; html += "</head><body onload='document.forms[0].submit()'>"; html += string.Format("<form name='PostForm' method='POST' action='{0}'>", remoteUrl); foreach (string key in collections.Keys) { html += string.Format("<input name='{0}' type='text' value='{1}'>", key, collections[key]); } html += "</form></body></html>"; Response.Clear(); Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1"); Response.HeaderEncoding = Encoding.GetEncoding("ISO-8859-1"); Response.Charset = "ISO-8859-1"; Response.Write(html); Response.End(); }
POST先(=http://localhost:58441/Page2_CS.aspx)のコードは下記の通りです。
page2_CS.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page2_CS.aspx.cs" Inherits="Page2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> FirstName: </td> <td> <asp:Label ID="lblFirstName" runat="server" /> </td> </tr> <tr> <td> LastName: </td> <td> <asp:Label ID="lblLastName" runat="server" /> </td> </tr> </table> </form> </body> </html>
page2_CS.aspx.cs
public partial class Page2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod == "GET") { // The action is a GET. } if (Request.Form.Count > 0) { lblFirstName.Text = Request.Form["FirstName"]; lblLastName.Text = Request.Form["LastName"]; } } }
Request.Form["FirstName"]の値を取得したいと思っています。
###試したこと
Server.Transfer()ではRequest.HttpMethod = "POST"で遷移できています。
ただ、別サーバ間でPOSTでデータの受け渡しをする必要があるので、
Server.Transfer()以外の方法で試しています。
###補足情報(言語/FW/ツール等のバージョンなど)
ASP.net 4.5 .net FrameWork 4.5.2

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/31 10:30
退会済みユーザー
2017/10/31 13:14
2017/10/31 15:51
退会済みユーザー
2017/11/01 01:45
2017/11/01 05:40
退会済みユーザー
2017/11/01 07:06
2017/11/01 08:45