Internet Explorer cannot display the webpage

2019-05-26 10:29发布

问题:

Im Not sure what this is telling me? I have this in place:

<system.web>
    <customErrors mode="Off"/>

When I click on a button that it is supposed to upload a file. I get the error Listed above when doing so. I am running on my local machine. I try to debug it and I get the error and not my break point. I put the "hello" line in thinking it was trying to evaluate the "if" statement before doing my breakpoint. Still fails and not sure why.

 protected void btnUpload_Click(object sender, EventArgs e)
 {
     string a = "hello";
     if (FuQuote.HasFile)
     {
         string path = "~/Quotes/" + FuQuote.FileName;
         FuQuote.SaveAs(MapPath(path));
     }
 } 

This problem can be caused by a variety of issues, including:

  • Internet connectivity has been lost.
  • The website is temporarily unavailable.
  • The Domain Name Server (DNS) is not reachable.
  • The Domain Name Server (DNS) does not have a listing for the website's domain.
  • There might be a typing error in the address.
  • If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.

回答1:

What is your maxRequestLength value set to in your web.config? You are probably selecting a file that is bigger than the maxRequestLength value.

<system.web>
    <httpRuntime maxRequestLength="4096"/>
</system.web>


回答2:

The max request length is creating trouble for you. By default the maximum allowed file upload size is 4MB. If you try to upload a file with higher size the connection will reset and won't reach the "HasFile" code. Check the size of the file you tried uploading and try with a smaller file. You can increase the file size limit by adding

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="SIZE" />
  </system.web>
</configuration>

The tags and will be there by default. If it is there in web.config add the line to it. SIZE should be replaced with the size limit.

NOTE : size is entered in KB.

Also, its always better to write such a code inside a try-catch block. There are n-number of possibilities for an exception to occur.

protected void btnUpload_Click(object sender, EventArgs e)
 {
     try
     {
         string a = "hello";
         if (FuQuote.HasFile)
         {
             string path = "~/Quotes/" + FuQuote.FileName;
             FuQuote.SaveAs(MapPath(path));
         }
     }catch(Exception ex)
     {
         // Exception handling code goes here.
     }
 } 


回答3:

The FileName property of the upload control returns the full path to the file. You need to parse the file name as part of your upload logic. I think you need to use FuQuote.PostedFile.FileName too.

Import the System.IO namespace and do this:

string path = String.Format("~/Quotes/{0}", Path.GetFileName(FuQuote.PostedFile.FileName));

FuQuote.SaveAs(Server.MapPath(path));