POST在ASP.net应用程序中作为GET HTTP请求命中

时间:2016-06-11 15:41:27

标签: c# asp.net http-post

我有一个应用程序需要接受来自客户端应用程序的POST请求,但它接受它作为GET请求,异常为"读取超时..."和#34;写出时间......" 。将客户端作为Fidler POSt请求,但同样的问题仍然存在。 请帮我解决这个问题。

我是否需要执行任何IIS或web.config设置?

在IIS 7和8.5中试用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication3
{
    public partial class WebForm1 : System.Web.UI.Page
    {
           protected void Page_Load(object sender, EventArgs e)
        {
            //var str = Request.QueryString[0];
                       Request.InputStream.Position = 0;
            System.IO.Stream objInputStream = Request.InputStream;
            byte[] arr_bInputBuffer = new byte[objInputStream.Length];
            objInputStream.Read(arr_bInputBuffer, 0, (int)(objInputStream.Length));

            byte[] arr_bOutputBuffer = getByteFromString("Request Executed and length: " + objInputStream.Length + ", Date: " + DateTime.Now);
            Response.OutputStream.Write(arr_bOutputBuffer, 0, arr_bOutputBuffer.Length);
            Request.InputStream.Flush();
            this.Request.InputStream.Close();
        }

            public static byte[] getByteFromString(String strXmlString)
        {
            byte[] arr_bArray;
            try
            {
                arr_bArray = new byte[strXmlString.Length];
                for (int nIndex = 0; nIndex < strXmlString.Length; nIndex++)
                {
                    arr_bArray[nIndex] = System.Convert.ToByte(strXmlString[nIndex]);
                }
            }
            catch (Exception e)
            {
                throw;
            }
            return arr_bArray;
        }


    }
}

的Web.Config

<?xml version="1.0" encoding="utf-8"?>
<!--
  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=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-WebApplication3-20160611124101.mdf;Initial Catalog=aspnet-WebApplication3-20160611124101;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
  </connectionStrings>


  <system.webServer>
    <security>
      <requestFiltering allowDoubleEscaping="true">
        <!-- block /CFIDE -->
        <!--<denyUrlSequences>
          <add sequence="/CFIDE"/>
        </denyUrlSequences>
        --><!-- block all file extensions except cfm,js,css,html --><!--
        <fileExtensions allowUnlisted="false" applyToWebDAV="true">
          <add fileExtension=".cfm" allowed="true" />
          <add fileExtension=".js" allowed="true" />
          <add fileExtension=".css" allowed="true" />
          <add fileExtension=".html" allowed="true" />
        </fileExtensions>-->
        <!-- hide configuration dir -->
        <!--<hiddenSegments applyToWebDAV="true">-->
          <!--<add segment="configuration" />
        </hiddenSegments>-->
        <!-- limit post size to 10mb, query string to 256 chars, url to 1024 chars -->
        <requestLimits maxAllowedContentLength="1073741824" maxUrl="1073741824" maxQueryString="1073741824">

        </requestLimits>

      <!-- only allow GET,POST verbs -->
        <verbs allowUnlisted="true">
          <add verb="POST" allowed="true" />
          <add verb="GET" allowed="true" />
         <add verb="DEBUG" allowed="true" />

        </verbs>
                <fileExtensions>
                    <remove fileExtension=".cs" />
                    <add fileExtension=".aspx" allowed="true" />
                    <add fileExtension=".cs" allowed="true" />
                </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpSoap" />
        <add name="HttpPost" />
        <add name="HttpGet" />
        <add name="HttpPostLocalhost" />
        <!-- Documentation enables the documentation/test pages -->
        <add name="Documentation" />
      </protocols>
    </webServices>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <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>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
  <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="v12.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

0 个答案:

没有答案