2015-04-01 46 views
0

我對MVC應用程序有一個操作,我需要做同樣的事情,但在使用Web窗體的應用程序中。我很抱歉,如果這是一個愚蠢的事情,但我不是在網絡形式的專家。將發佈後操作遷移到網絡表單

這是我的操作:

[HttpPost] 
public ActionResult Login(string userName) 
{ 

} 

我怎麼做HttpPost在Web表單?

UPDATE

我發現,如果我把這個(Page.Request [「登錄」])在我的代碼我能夠檢索所有崗位參數。

回答

1

我相信你想使用HttpWebPost Class類。

喜歡的東西

private void OnPostInfoClick(object sender, System.EventArgs e) 
    { 
     string strId = UserId_TextBox.Text; 
     string strName = Name_TextBox.Text; 

     ASCIIEncoding encoding=new ASCIIEncoding(); 
     string postData="userid="+strId; 
     postData += ("&username="+strName); 
     byte[] data = encoding.GetBytes(postData); 

     // Prepare web request... 
     HttpWebRequest myRequest = 
     (HttpWebRequest)WebRequest.Create("http://localhost/Default.aspx"); 
     myRequest.Method = "POST"; 
     myRequest.ContentType="application/x-www-form-urlencoded"; 
     myRequest.ContentLength = data.Length; 
     Stream newStream=myRequest.GetRequestStream(); 

     // Send the data. 
     newStream.Write(data,0,data.Length); 
     newStream.Close(); 
    } 
+0

謝謝。我用它來模擬一個帖子重定向。 – 2015-04-01 12:51:51