【问题标题】:System.Net.WebException: The remote server returned an error: (500) Internal Server Error.System.Net.WebException:远程服务器返回错误:(500)内部服务器错误。
【发布时间】:2015-05-03 17:30:41
【问题描述】:

System.Net.WebException:远程服务器返回错误:(500)内部服务器错误。在 System.Net.HttpWebRequest.GetResponse() 在 SMS.Testpage.btnsubmit_Click(Object sender, EventArgs e)

这是我将文件上传到远程服务器时遇到的错误。就本地主机而言,它工作正常并返回我期望的相同 wat,但我不明白为什么它会这样,如果有人对我的错误有想法,请让我摆脱这个大问题。自 3 周以来,我一直在为这个问题苦苦挣扎。

这是我的网络配置代码---

<configuration>
  <connectionStrings>
    <add name="mydbcon" connectionString="Data Source=xyz;Initial Catalog=smspro;Persist Security Info=True;User ID=xyz;Password=xyz" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime />
     <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    <!--<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>-->
  </system.web>
  <appSettings />

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="epBasicHttp" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="tcpBinding" receiveTimeout="00:15:00" sendTimeout="00:15:00"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <security mode="None">
            <transport clientCredentialType="None" protectionLevel="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
        <!--<binding name="epNetTcp" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/`enter code here`>
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
            <message clientCredentialType="Windows"/>
          </security>
        </binding>-->
      </netTcpBinding>
    </bindings>
    <services>
      <service name="SMS.Services.Communication">
        <endpoint address="http://localhost:3053/Services/Communication.svc" binding="webHttpBinding" contract="SMS.Services.ICommunication"
                  behaviorConfiguration="Web"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="Web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment  minFreeMemoryPercentageToActivateService="0"/>
    <!--<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />-->
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

【问题讨论】:

  • 调试你的服务器或查看日志找到确切的问题,没有信息是不可能找到问题的。

标签: c# asp.net .net


【解决方案1】:

您的代码在服务器中运行时崩溃。您需要获取有关崩溃原因的更多详细信息才能修复它。首先要做的是更新网络配置,以便它可以为您提供有关错误的更多详细信息。将 customErrors 元素的 mode 属性值设置为“Off”

<system.web>
    <customErrors mode="Off" />
    //Other items goes here
</system.web>

我能想到的可能原因是

  1. 您的连接字符串不正确。有的代码没有 能够访问您的数据库服务器。仔细检查数据库服务器名称是 正确。

  2. 代码无权写入某些目录(当您进行文件上传时,您需要确保更新目录权限,以便 ASP.NET 可以写入该文件夹)。

【讨论】:

  • 我没有得到问题..这个问题在哪里,数据库部分工作正常。这是 web cofig 的代码之一,在本地主机上运行良好..
  • 我不知道directoeies的权限,因为它适用于其他文件看起来不错..