天天看點

asp.net使用post方式action到另一個頁面,在另一個頁面接受form表單的值!(報錯,已解決!)

我想用post的方式把一個頁面表單的值,傳到另一個頁面。當我點選Default.aspx的Send送出按鈕時,這個時候會action到Default2.aspx頁面,在這個時候就報錯了,報的錯誤是:Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey>configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster(不了解為什麼是這樣!)

解決辦法:在要接受的頁面Default2.aspx加上<%@ Page Language="C#"  enableViewStateMac="false" %> 這個,就可以了!

Default.aspx頁面的代碼:

Default2.aspx頁面代碼:

string name = Request["name"];

Response.Write(name + "<br>");

Response.Write("你使用的是" + Request.RequestType + "方式傳送資料");

隻是在page_load裡面加了接受form表單值的代碼!

繼續閱讀