C# 版本的 WebForms 页面不工作,VB 版本是
C# version of WebForms page not working, VB version is
我有两个版本的网络表单。原文,在VB。和新的,在 C# 中。它们本质上做同样的事情,但语言不同,C# 版本在功能和可读性方面略有改进。通过 @Page 标记上的 autoeventwireup 属性,每一个 .aspx 页面本身的差异都是不同的。现在,当我尝试 运行 VB 版本时,我得到了我正在寻找的结果。 C# 版本什么都不做。在每个页面的日志中,我看到 VB 版本从调用者那里得到一个 POST,而 C# 版本从调用者那里得到一个 GET。因此 Request.Form 值中的 none 可用于 C# 版本。部署后的两个页面均由单独的 Web 应用程序调用。
VB版本page.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Custom Label Generator.aspx.vb" 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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
C# 版本page.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Custom Label Generator.aspx.cs" Inherits="CustomLabelGenerator.Custom_Label_Generator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Custom Label Generator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
VB 版本代码隐藏:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'LogEvent("Request to print: " & Date.Today)
Try
If Request.Form.Count <= 0 Then
LogEvent("No label data was submitted with the request.")
Exit Sub
End If
'WRITE LABEL DATA BACK TO REQUESTING CLIENT
Me.Response.Clear()
Me.Response.ContentType = "text/plain"
Me.Response.BinaryWrite(System.Text.Encoding.Default.GetBytes(sLabelCode))
Me.Response.Flush()
Catch ex As Exception
LogEvent("Problem generating custom labels. More information: " + ex.Message)
End Try
End Sub
C# 版本代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
LogHelper.LogEvent("Request to print at: " + DateTime.Now);
try
{
if(Request.Form.Count <= 0)
{
LogHelper.LogEvent("No label data was submitted with the request");
return;
}
Response.Clear();
Response.ContentType = "text/plain";
Response.BinaryWrite(Encoding.Default.GetBytes(labelCode));
Response.Flush();
}
catch (Exception ex)
{
LogHelper.LogEvent("Problem generating custom labels. More information :: " + ex.Message);
}
finally
{
LogHelper.CleanupOldLogs();
}
}
我目前在这两个里面都有一堆代码吐出来所有我能想到的请求信息。我也试过撤消 autoeventwireup,但在 C# 中似乎没有可靠的等价物。我想知道这作为 WebAPI 调用是否会更好,强制它只接受 POST,而不是与任何其他 kruft 混淆。不过,我不确定我是否有时间进行那种级别的转换,因此我们将不胜感激基于网络表单的解决方案!
更新:转储 Request.Form.VB 版本的密钥(减去我需要的 USEFUL 密钥)
9/23/2015 2:25:10 PM,ALL_HTTP => HTTP_CONNECTION:Keep-Alive
HTTP_CONTENT_LENGTH:1371
HTTP_CONTENT_TYPE:application/x-www-form-urlencoded
HTTP_EXPECT:100-continue
HTTP_HOST:localhost
9/23/2015 2:25:10 PM,ALL_RAW => Connection: Keep-Alive
Content-Length: 1371
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
Host: localhost
9/23/2015 2:25:10 PM,APPL_MD_PATH => /LM/W3SVC/1/ROOT/Custom Label Generator
9/23/2015 2:25:10 PM,APPL_PHYSICAL_PATH => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\
9/23/2015 2:25:10 PM,AUTH_TYPE =>
9/23/2015 2:25:10 PM,AUTH_USER =>
9/23/2015 2:25:10 PM,AUTH_PASSWORD =>
9/23/2015 2:25:10 PM,LOGON_USER =>
9/23/2015 2:25:10 PM,REMOTE_USER =>
9/23/2015 2:25:10 PM,CERT_COOKIE =>
9/23/2015 2:25:10 PM,CERT_FLAGS =>
9/23/2015 2:25:10 PM,CERT_ISSUER =>
9/23/2015 2:25:10 PM,CERT_KEYSIZE =>
9/23/2015 2:25:10 PM,CERT_SECRETKEYSIZE =>
9/23/2015 2:25:10 PM,CERT_SERIALNUMBER =>
9/23/2015 2:25:10 PM,CERT_SERVER_ISSUER =>
9/23/2015 2:25:10 PM,CERT_SERVER_SUBJECT =>
9/23/2015 2:25:10 PM,CERT_SUBJECT =>
9/23/2015 2:25:10 PM,CONTENT_LENGTH => 1371
9/23/2015 2:25:10 PM,CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:25:10 PM,GATEWAY_INTERFACE => CGI/1.1
9/23/2015 2:25:10 PM,HTTPS => off
9/23/2015 2:25:10 PM,HTTPS_KEYSIZE =>
9/23/2015 2:25:10 PM,HTTPS_SECRETKEYSIZE =>
9/23/2015 2:25:10 PM,HTTPS_SERVER_ISSUER =>
9/23/2015 2:25:10 PM,HTTPS_SERVER_SUBJECT =>
9/23/2015 2:25:10 PM,INSTANCE_ID => 1
9/23/2015 2:25:10 PM,INSTANCE_META_PATH => /LM/W3SVC/1
9/23/2015 2:25:10 PM,LOCAL_ADDR => ::1
9/23/2015 2:25:10 PM,PATH_INFO => /Custom Label Generator/Custom Label Generator.aspx
9/23/2015 2:25:10 PM,PATH_TRANSLATED => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\Custom Label Generator.aspx
9/23/2015 2:25:10 PM,QUERY_STRING =>
9/23/2015 2:25:10 PM,REMOTE_ADDR => ::1
9/23/2015 2:25:10 PM,REMOTE_HOST => ::1
9/23/2015 2:25:10 PM,REMOTE_PORT => 59112
9/23/2015 2:25:10 PM,**REQUEST_METHOD => POST**
9/23/2015 2:25:10 PM,SCRIPT_NAME => /Custom Label Generator/Custom Label Generator.aspx
9/23/2015 2:25:10 PM,SERVER_NAME => localhost
9/23/2015 2:25:10 PM,SERVER_PORT => 80
9/23/2015 2:25:10 PM,SERVER_PORT_SECURE => 0
9/23/2015 2:25:10 PM,SERVER_PROTOCOL => HTTP/1.1
9/23/2015 2:25:10 PM,SERVER_SOFTWARE => Microsoft-IIS/7.5
9/23/2015 2:25:10 PM,URL => /Custom Label Generator/Custom Label Generator.aspx
9/23/2015 2:25:10 PM,HTTP_CONNECTION => Keep-Alive
9/23/2015 2:25:10 PM,HTTP_CONTENT_LENGTH => 1371
9/23/2015 2:25:10 PM,HTTP_CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:25:10 PM,HTTP_EXPECT => 100-continue
9/23/2015 2:25:10 PM,HTTP_HOST => localhost
Request.Params.Keys的C#版本转储(其他部分为空白)
9/23/2015 2:17:04 PM --- Request to print at: 9/23/2015 2:17:04 PM
9/23/2015 2:17:04 PM --- Request.Params.Keys:
9/23/2015 2:17:04 PM --- ALL_HTTP => HTTP_CONTENT_TYPE:application/x-www-form-urlencoded
HTTP_HOST:localhost
9/23/2015 2:17:04 PM --- ALL_RAW => Content-Type: application/x-www-form-urlencoded
Host: localhost
9/23/2015 2:17:04 PM --- APPL_MD_PATH => /LM/W3SVC/1/ROOT/Custom Label Generator
9/23/2015 2:17:04 PM --- APPL_PHYSICAL_PATH => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\
9/23/2015 2:17:04 PM --- AUTH_TYPE =>
9/23/2015 2:17:04 PM --- AUTH_USER =>
9/23/2015 2:17:04 PM --- AUTH_PASSWORD =>
9/23/2015 2:17:05 PM --- LOGON_USER =>
9/23/2015 2:17:05 PM --- REMOTE_USER =>
9/23/2015 2:17:05 PM --- CERT_COOKIE =>
9/23/2015 2:17:05 PM --- CERT_FLAGS =>
9/23/2015 2:17:05 PM --- CERT_ISSUER =>
9/23/2015 2:17:05 PM --- CERT_KEYSIZE =>
9/23/2015 2:17:05 PM --- CERT_SECRETKEYSIZE =>
9/23/2015 2:17:05 PM --- CERT_SERIALNUMBER =>
9/23/2015 2:17:05 PM --- CERT_SERVER_ISSUER =>
9/23/2015 2:17:05 PM --- CERT_SERVER_SUBJECT =>
9/23/2015 2:17:05 PM --- CERT_SUBJECT =>
9/23/2015 2:17:05 PM --- CONTENT_LENGTH => 0
9/23/2015 2:17:05 PM --- CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:17:05 PM --- GATEWAY_INTERFACE => CGI/1.1
9/23/2015 2:17:05 PM --- HTTPS => off
9/23/2015 2:17:05 PM --- HTTPS_KEYSIZE =>
9/23/2015 2:17:05 PM --- HTTPS_SECRETKEYSIZE =>
9/23/2015 2:17:05 PM --- HTTPS_SERVER_ISSUER =>
9/23/2015 2:17:05 PM --- HTTPS_SERVER_SUBJECT =>
9/23/2015 2:17:05 PM --- INSTANCE_ID => 1
9/23/2015 2:17:05 PM --- INSTANCE_META_PATH => /LM/W3SVC/1
9/23/2015 2:17:05 PM --- LOCAL_ADDR => ::1
9/23/2015 2:17:05 PM --- PATH_INFO => /Custom Label Generator/Custom Label Generator
9/23/2015 2:17:05 PM --- PATH_TRANSLATED => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\Custom Label Generator
9/23/2015 2:17:05 PM --- QUERY_STRING =>
9/23/2015 2:17:05 PM --- REMOTE_ADDR => ::1
9/23/2015 2:17:05 PM --- REMOTE_HOST => ::1
9/23/2015 2:17:05 PM --- REMOTE_PORT => 58997
9/23/2015 2:17:05 PM --- **REQUEST_METHOD => GET**
9/23/2015 2:17:05 PM --- SCRIPT_NAME => /Custom Label Generator/Custom Label Generator
9/23/2015 2:17:05 PM --- SERVER_NAME => localhost
9/23/2015 2:17:05 PM --- SERVER_PORT => 80
9/23/2015 2:17:05 PM --- SERVER_PORT_SECURE => 0
9/23/2015 2:17:05 PM --- SERVER_PROTOCOL => HTTP/1.1
9/23/2015 2:17:05 PM --- SERVER_SOFTWARE => Microsoft-IIS/7.5
9/23/2015 2:17:05 PM --- URL => /Custom Label Generator/Custom Label Generator
9/23/2015 2:17:05 PM --- HTTP_CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:17:05 PM --- HTTP_HOST => localhost
9/23/2015 2:17:05 PM --- /****************** Request.Form.Keys: ***********************/
9/23/2015 2:17:05 PM --- /****************** Request.Form.AllKeys: ***********************/
9/23/2015 2:17:05 PM --- /****************** Request.QueryString.Keys: ***********************/
马特,你为什么不在你的表单中添加一个方法="POST"?
<form id="form1" runat="server" method="post">
马特,
我也遇到过 'POST' 神秘地变成 'GET' 之前。它可能由于 VS2013 及更高版本中默认的 FriendlyUrlSettings 而被重定向。
一种解决方法:转到 RouteConfig.ResgisterRoutes 中的 App_Start 文件夹并设置 settings.AutoRedirectMode = RedirectMode.Off
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Off;
routes.EnableFriendlyUrls(settings);
}
}
查看此 link 以获取有关 FriendlyUrls 的更多信息:http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx
马特,
这是故意的吗?
VB
Inherits="_Default"
C#
继承="CustomLabelGenerator.Custom_Label_Generator"
马特,
此行为的原因是试图减少多次提交表单的机会。这背后的理论被称为 POST-REDIRECT-GET。来自 https://en.wikipedia.org/wiki/Post/Redirect/Get:
When a web form is submitted to a server through an HTTP POST request, a web user that attempts to refresh the server response in certain user agents can cause the contents of the original HTTP POST request to be resubmitted, possibly causing undesired results, such as a duplicate web purchase.
To avoid this problem, many web developers use the PRG pattern1 — instead of returning a web page directly, the POST operation returns a redirection command. The HTTP 1.1 specification introduced the HTTP 303 ("See other") response code to ensure that in this situation, the web user's browser can safely refresh the server response without causing the initial HTTP POST request to be resubmitted. However most common commercial applications in use today (new and old alike) still continue to issue HTTP 302 ("Found") responses in these situations.
我有两个版本的网络表单。原文,在VB。和新的,在 C# 中。它们本质上做同样的事情,但语言不同,C# 版本在功能和可读性方面略有改进。通过 @Page 标记上的 autoeventwireup 属性,每一个 .aspx 页面本身的差异都是不同的。现在,当我尝试 运行 VB 版本时,我得到了我正在寻找的结果。 C# 版本什么都不做。在每个页面的日志中,我看到 VB 版本从调用者那里得到一个 POST,而 C# 版本从调用者那里得到一个 GET。因此 Request.Form 值中的 none 可用于 C# 版本。部署后的两个页面均由单独的 Web 应用程序调用。
VB版本page.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Custom Label Generator.aspx.vb" 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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
C# 版本page.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Custom Label Generator.aspx.cs" Inherits="CustomLabelGenerator.Custom_Label_Generator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Custom Label Generator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
VB 版本代码隐藏:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'LogEvent("Request to print: " & Date.Today)
Try
If Request.Form.Count <= 0 Then
LogEvent("No label data was submitted with the request.")
Exit Sub
End If
'WRITE LABEL DATA BACK TO REQUESTING CLIENT
Me.Response.Clear()
Me.Response.ContentType = "text/plain"
Me.Response.BinaryWrite(System.Text.Encoding.Default.GetBytes(sLabelCode))
Me.Response.Flush()
Catch ex As Exception
LogEvent("Problem generating custom labels. More information: " + ex.Message)
End Try
End Sub
C# 版本代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
LogHelper.LogEvent("Request to print at: " + DateTime.Now);
try
{
if(Request.Form.Count <= 0)
{
LogHelper.LogEvent("No label data was submitted with the request");
return;
}
Response.Clear();
Response.ContentType = "text/plain";
Response.BinaryWrite(Encoding.Default.GetBytes(labelCode));
Response.Flush();
}
catch (Exception ex)
{
LogHelper.LogEvent("Problem generating custom labels. More information :: " + ex.Message);
}
finally
{
LogHelper.CleanupOldLogs();
}
}
我目前在这两个里面都有一堆代码吐出来所有我能想到的请求信息。我也试过撤消 autoeventwireup,但在 C# 中似乎没有可靠的等价物。我想知道这作为 WebAPI 调用是否会更好,强制它只接受 POST,而不是与任何其他 kruft 混淆。不过,我不确定我是否有时间进行那种级别的转换,因此我们将不胜感激基于网络表单的解决方案!
更新:转储 Request.Form.VB 版本的密钥(减去我需要的 USEFUL 密钥)
9/23/2015 2:25:10 PM,ALL_HTTP => HTTP_CONNECTION:Keep-Alive
HTTP_CONTENT_LENGTH:1371
HTTP_CONTENT_TYPE:application/x-www-form-urlencoded
HTTP_EXPECT:100-continue
HTTP_HOST:localhost
9/23/2015 2:25:10 PM,ALL_RAW => Connection: Keep-Alive
Content-Length: 1371
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
Host: localhost
9/23/2015 2:25:10 PM,APPL_MD_PATH => /LM/W3SVC/1/ROOT/Custom Label Generator
9/23/2015 2:25:10 PM,APPL_PHYSICAL_PATH => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\
9/23/2015 2:25:10 PM,AUTH_TYPE =>
9/23/2015 2:25:10 PM,AUTH_USER =>
9/23/2015 2:25:10 PM,AUTH_PASSWORD =>
9/23/2015 2:25:10 PM,LOGON_USER =>
9/23/2015 2:25:10 PM,REMOTE_USER =>
9/23/2015 2:25:10 PM,CERT_COOKIE =>
9/23/2015 2:25:10 PM,CERT_FLAGS =>
9/23/2015 2:25:10 PM,CERT_ISSUER =>
9/23/2015 2:25:10 PM,CERT_KEYSIZE =>
9/23/2015 2:25:10 PM,CERT_SECRETKEYSIZE =>
9/23/2015 2:25:10 PM,CERT_SERIALNUMBER =>
9/23/2015 2:25:10 PM,CERT_SERVER_ISSUER =>
9/23/2015 2:25:10 PM,CERT_SERVER_SUBJECT =>
9/23/2015 2:25:10 PM,CERT_SUBJECT =>
9/23/2015 2:25:10 PM,CONTENT_LENGTH => 1371
9/23/2015 2:25:10 PM,CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:25:10 PM,GATEWAY_INTERFACE => CGI/1.1
9/23/2015 2:25:10 PM,HTTPS => off
9/23/2015 2:25:10 PM,HTTPS_KEYSIZE =>
9/23/2015 2:25:10 PM,HTTPS_SECRETKEYSIZE =>
9/23/2015 2:25:10 PM,HTTPS_SERVER_ISSUER =>
9/23/2015 2:25:10 PM,HTTPS_SERVER_SUBJECT =>
9/23/2015 2:25:10 PM,INSTANCE_ID => 1
9/23/2015 2:25:10 PM,INSTANCE_META_PATH => /LM/W3SVC/1
9/23/2015 2:25:10 PM,LOCAL_ADDR => ::1
9/23/2015 2:25:10 PM,PATH_INFO => /Custom Label Generator/Custom Label Generator.aspx
9/23/2015 2:25:10 PM,PATH_TRANSLATED => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\Custom Label Generator.aspx
9/23/2015 2:25:10 PM,QUERY_STRING =>
9/23/2015 2:25:10 PM,REMOTE_ADDR => ::1
9/23/2015 2:25:10 PM,REMOTE_HOST => ::1
9/23/2015 2:25:10 PM,REMOTE_PORT => 59112
9/23/2015 2:25:10 PM,**REQUEST_METHOD => POST**
9/23/2015 2:25:10 PM,SCRIPT_NAME => /Custom Label Generator/Custom Label Generator.aspx
9/23/2015 2:25:10 PM,SERVER_NAME => localhost
9/23/2015 2:25:10 PM,SERVER_PORT => 80
9/23/2015 2:25:10 PM,SERVER_PORT_SECURE => 0
9/23/2015 2:25:10 PM,SERVER_PROTOCOL => HTTP/1.1
9/23/2015 2:25:10 PM,SERVER_SOFTWARE => Microsoft-IIS/7.5
9/23/2015 2:25:10 PM,URL => /Custom Label Generator/Custom Label Generator.aspx
9/23/2015 2:25:10 PM,HTTP_CONNECTION => Keep-Alive
9/23/2015 2:25:10 PM,HTTP_CONTENT_LENGTH => 1371
9/23/2015 2:25:10 PM,HTTP_CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:25:10 PM,HTTP_EXPECT => 100-continue
9/23/2015 2:25:10 PM,HTTP_HOST => localhost
Request.Params.Keys的C#版本转储(其他部分为空白)
9/23/2015 2:17:04 PM --- Request to print at: 9/23/2015 2:17:04 PM
9/23/2015 2:17:04 PM --- Request.Params.Keys:
9/23/2015 2:17:04 PM --- ALL_HTTP => HTTP_CONTENT_TYPE:application/x-www-form-urlencoded
HTTP_HOST:localhost
9/23/2015 2:17:04 PM --- ALL_RAW => Content-Type: application/x-www-form-urlencoded
Host: localhost
9/23/2015 2:17:04 PM --- APPL_MD_PATH => /LM/W3SVC/1/ROOT/Custom Label Generator
9/23/2015 2:17:04 PM --- APPL_PHYSICAL_PATH => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\
9/23/2015 2:17:04 PM --- AUTH_TYPE =>
9/23/2015 2:17:04 PM --- AUTH_USER =>
9/23/2015 2:17:04 PM --- AUTH_PASSWORD =>
9/23/2015 2:17:05 PM --- LOGON_USER =>
9/23/2015 2:17:05 PM --- REMOTE_USER =>
9/23/2015 2:17:05 PM --- CERT_COOKIE =>
9/23/2015 2:17:05 PM --- CERT_FLAGS =>
9/23/2015 2:17:05 PM --- CERT_ISSUER =>
9/23/2015 2:17:05 PM --- CERT_KEYSIZE =>
9/23/2015 2:17:05 PM --- CERT_SECRETKEYSIZE =>
9/23/2015 2:17:05 PM --- CERT_SERIALNUMBER =>
9/23/2015 2:17:05 PM --- CERT_SERVER_ISSUER =>
9/23/2015 2:17:05 PM --- CERT_SERVER_SUBJECT =>
9/23/2015 2:17:05 PM --- CERT_SUBJECT =>
9/23/2015 2:17:05 PM --- CONTENT_LENGTH => 0
9/23/2015 2:17:05 PM --- CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:17:05 PM --- GATEWAY_INTERFACE => CGI/1.1
9/23/2015 2:17:05 PM --- HTTPS => off
9/23/2015 2:17:05 PM --- HTTPS_KEYSIZE =>
9/23/2015 2:17:05 PM --- HTTPS_SECRETKEYSIZE =>
9/23/2015 2:17:05 PM --- HTTPS_SERVER_ISSUER =>
9/23/2015 2:17:05 PM --- HTTPS_SERVER_SUBJECT =>
9/23/2015 2:17:05 PM --- INSTANCE_ID => 1
9/23/2015 2:17:05 PM --- INSTANCE_META_PATH => /LM/W3SVC/1
9/23/2015 2:17:05 PM --- LOCAL_ADDR => ::1
9/23/2015 2:17:05 PM --- PATH_INFO => /Custom Label Generator/Custom Label Generator
9/23/2015 2:17:05 PM --- PATH_TRANSLATED => C:\Program Files (x86)\AgileElite\Projects Server\ContentLabelGenerator\Custom Label Generator
9/23/2015 2:17:05 PM --- QUERY_STRING =>
9/23/2015 2:17:05 PM --- REMOTE_ADDR => ::1
9/23/2015 2:17:05 PM --- REMOTE_HOST => ::1
9/23/2015 2:17:05 PM --- REMOTE_PORT => 58997
9/23/2015 2:17:05 PM --- **REQUEST_METHOD => GET**
9/23/2015 2:17:05 PM --- SCRIPT_NAME => /Custom Label Generator/Custom Label Generator
9/23/2015 2:17:05 PM --- SERVER_NAME => localhost
9/23/2015 2:17:05 PM --- SERVER_PORT => 80
9/23/2015 2:17:05 PM --- SERVER_PORT_SECURE => 0
9/23/2015 2:17:05 PM --- SERVER_PROTOCOL => HTTP/1.1
9/23/2015 2:17:05 PM --- SERVER_SOFTWARE => Microsoft-IIS/7.5
9/23/2015 2:17:05 PM --- URL => /Custom Label Generator/Custom Label Generator
9/23/2015 2:17:05 PM --- HTTP_CONTENT_TYPE => application/x-www-form-urlencoded
9/23/2015 2:17:05 PM --- HTTP_HOST => localhost
9/23/2015 2:17:05 PM --- /****************** Request.Form.Keys: ***********************/
9/23/2015 2:17:05 PM --- /****************** Request.Form.AllKeys: ***********************/
9/23/2015 2:17:05 PM --- /****************** Request.QueryString.Keys: ***********************/
马特,你为什么不在你的表单中添加一个方法="POST"?
<form id="form1" runat="server" method="post">
马特, 我也遇到过 'POST' 神秘地变成 'GET' 之前。它可能由于 VS2013 及更高版本中默认的 FriendlyUrlSettings 而被重定向。
一种解决方法:转到 RouteConfig.ResgisterRoutes 中的 App_Start 文件夹并设置 settings.AutoRedirectMode = RedirectMode.Off
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Off;
routes.EnableFriendlyUrls(settings);
}
}
查看此 link 以获取有关 FriendlyUrls 的更多信息:http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx
马特,
这是故意的吗?
VB Inherits="_Default"
C# 继承="CustomLabelGenerator.Custom_Label_Generator"
马特,
此行为的原因是试图减少多次提交表单的机会。这背后的理论被称为 POST-REDIRECT-GET。来自 https://en.wikipedia.org/wiki/Post/Redirect/Get:
When a web form is submitted to a server through an HTTP POST request, a web user that attempts to refresh the server response in certain user agents can cause the contents of the original HTTP POST request to be resubmitted, possibly causing undesired results, such as a duplicate web purchase.
To avoid this problem, many web developers use the PRG pattern1 — instead of returning a web page directly, the POST operation returns a redirection command. The HTTP 1.1 specification introduced the HTTP 303 ("See other") response code to ensure that in this situation, the web user's browser can safely refresh the server response without causing the initial HTTP POST request to be resubmitted. However most common commercial applications in use today (new and old alike) still continue to issue HTTP 302 ("Found") responses in these situations.