通过GET(Request.QueryString)提交数据时,我收到的信息就好了。但是,使用POST,我根本没有收到任何信息(Request.Form)。
对于所有意图和目的,这是所有相关的代码。它主要是编辑的标记。
的Web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-SGAVotingSite-fd367704-e25a-4611-a728-e1192ddaf955;AttachDbFilename=|DataDirectory|\aspnet-SGAVotingSite-fd367704-e25a-4611-a728-e1192ddaf955.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5"/>
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
<add namespace="Microsoft.AspNet.Identity"/>
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<membership>
<providers>
<!--
ASP.NET Membership is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
-->
<clear/>
</providers>
</membership>
<profile>
<providers>
<!--
ASP.NET Membership Profile is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
-->
<clear/>
</providers>
</profile>
<roleManager>
<!--
ASP.NET Membership Role is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
-->
<providers>
<clear/>
</providers>
</roleManager>
<!--
If you are deploying to a cloud environment that has multiple web server instances,
you should change session state mode from "InProc" to "Custom". In addition,
change the connection string named "DefaultConnection" to connect to an instance
of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express.
-->
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection"/>
</providers>
</sessionState>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
Default.aspx标记:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" method="post">
<div style="margin: 12.5% 12.5% 12.5% 12.5%; vertical-align: middle; text-align: center; width: 75%; height: 50%; position: static;">
<asp:Panel ID="Panel1" runat="server" BorderStyle="Ridge" BorderWidth="5px" Direction="LeftToRight" Height="100%" HorizontalAlign="Center" Width="100%" Wrap="False">
<br />
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="72pt" ForeColor="#0066FF" Text="SGA Voting"></asp:Label>
<br />
<asp:Label ID="lblError" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="24pt" ForeColor="#FF6600"></asp:Label>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Username: " Font-Names="Verdana" Font-Size="24pt"></asp:Label>
<asp:TextBox ID="txtbxUsername" runat="server" AutoCompleteType="Disabled" Font-Names="Verdana" Font-Size="18pt"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Password: " Font-Names="Verdana" Font-Size="24pt"></asp:Label>
<asp:TextBox ID="txtbxPassword" runat="server" AutoCompleteType="Disabled" TextMode="Password" Font-Names="Verdana" Font-Size="18pt"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="btnLogin" runat="server" Text="Login" PostBackUrl="./Post.aspx" Font-Bold="True" Font-Names="Verdana" Font-Size="48pt" ForeColor="#0066FF" Height="100px" Width="90%"/>
<br />
<br />
</asp:Panel>
</div>
<div>
<asp:SqlDataSource ID="Votes" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [VoteTable]"></asp:SqlDataSource>
<asp:SqlDataSource ID="Config" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [ConfigTable]"></asp:SqlDataSource>
<asp:SqlDataSource ID="Users" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [UserTable]"></asp:SqlDataSource>
<asp:HiddenField ID="Directive" runat="server" Value="login" />
</div>
</form>
</body>
</html>
Post.aspx Markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Post.aspx.cs" Inherits="Post" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="VotingYears" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [YearTable]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SNums" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [SNumTable]"></asp:SqlDataSource>
<asp:SqlDataSource ID="People" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [PeopleTable]"></asp:SqlDataSource>
<asp:SqlDataSource ID="Positions" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [PositionTable]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Post.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Hello, you have reached POST. <a href='./Default.aspx'>Please leave.</a><br><br><br>");
NameValueCollection nvc = Request.Form;
if (!nvc.HasKeys())
{
Response.Write("Bad request? - ");
Response.Write(Request.Form.HasKeys());
}
}