我正在尝试将数据发布到跨域。如果表单没有使用 runat="server" 并且当表单使用 runat="server" 时它在发布时给出 500 内部错误,则它工作正常。
调试后,我发现问题出在页面上自动生成的 __viewstate 代码上。请找到以下代码。
客户端 HTML 实现:
<%@ Page Language="C#" CodeFile="Sample.aspx.cs" Inherits="Sample" %>
<!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>
<meta charset="utf-8">
<title>Untitled Page</title>
<link href="FileUpload.css" rel="stylesheet" type="text/css" />
<script id="template-upload" type="text/x-tmpl">
</script>
<script id="template-download" type="text/x-tmpl">
</script>
<script src="../../test/FileUpload/jQueryv1.6.2.js"></script>
<script src="fileupload-js/jquery.ui.widget.js"></script>
<script src="fileupload-js/tmpl.min.js"></script>
<script src="fileupload-js/jquery.fileupload.js"></script>
<script src="fileupload-js/jquery.fileupload-ui.js"></script>
<script src="fileupload-js/locale.js"></script>
<script src="fileupload-js/main.js"></script>
</head>
<body>
<form id="fileupload" method="POST" runat="server">
<CCAB.Web:FileUpload runat="server"/>
</form>
</body>
</html>
服务器端代码:
public partial class SaveFile : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Response.AddHeader("Access-Control-Allow-Origin", "*")
if (Request.HttpMethod == "GET" || Request.HttpMethod == "HEAD")
{
Response.Write("GET Success");
}
else
{
for (int i = 0; i < Request.Files.Count; i++)
{
string filename = Request.Files[i].FileName;
Request.Files[i].SaveAs(@"\\dev2\\share$\\Anna\\test\\" + filename);
Response.Write(filename);
Response.Write("Success");
}
}
}
}
您能否帮助我了解如何忽略来自客户端的隐藏视图状态代码或忽略服务器端的响应视图状态。
非常感谢安娜