Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.Net页面在本地工作,但推送到服务器时失败_C#_Asp.net - Fatal编程技术网

C# ASP.Net页面在本地工作,但推送到服务器时失败

C# ASP.Net页面在本地工作,但推送到服务器时失败,c#,asp.net,C#,Asp.net,我的站点在本地运行得非常完美,但每当我将其推送到服务器时,就会得到一个错误页面。这就是错误告诉我的,对我来说毫无意义。有人能帮忙吗 描述:服务器上发生应用程序错误。此应用程序的当前自定义错误设置阻止远程查看应用程序错误的详细信息(出于安全原因)。但是,本地服务器上运行的浏览器可以查看它 详细信息:要在远程计算机上查看此特定错误消息的详细信息,请在位于当前web应用程序根目录中的“web.config”配置文件中创建一个标记。然后,该标记的“mode”属性应设置为“Off” 注意:通过修改应用

我的站点在本地运行得非常完美,但每当我将其推送到服务器时,就会得到一个错误页面。这就是错误告诉我的,对我来说毫无意义。有人能帮忙吗

描述:服务器上发生应用程序错误。此应用程序的当前自定义错误设置阻止远程查看应用程序错误的详细信息(出于安全原因)。但是,本地服务器上运行的浏览器可以查看它

详细信息:要在远程计算机上查看此特定错误消息的详细信息,请在位于当前web应用程序根目录中的“web.config”配置文件中创建一个标记。然后,该标记的“mode”属性应设置为“Off”


注意:通过修改应用程序配置标记的“defaultRedirect”属性以指向自定义错误页URL,可以将当前看到的错误页替换为自定义错误页

<configuration>
<system.web>
    <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>


我建议使用global.asax中的application_error event捕获异常,然后在单独的error.txt日志文件中写入异常

void Application_Error(object sender, EventArgs ex) 
    { 
        Exception e = Server.GetLastError().GetBaseException();
            if (!e.Message.ToUpper().Contains("FILE DOES NOT EXIST."))
            {
               //This function is user defined Method which accepts string as inpout and writes it to error.txt file with date and time.
               WriteTo_ERROR_TXT_File(e.ToString());                              

              //Redirect to custom error display page               
               Server.Transfer("Error.aspx");    
            }        

    }

public void WriteTo_ERROR_TXT_File(string inputString)
    {
        using (System.IO.StreamWriter file = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath("Error.txt"), true))
        {
            file.WriteLine(inputString);
        }

    }

通过这种方式,您将捕获所有错误,如果您想要更健壮的解决方案,那么您可以使用ELMAH

,这是asp.net在从本地主机以外的其他设备查看时显示的默认通用错误消息。你的日志怎么说?服务器上的事件查看器是怎么说的?按照消息的建议执行,并在配置中包含
,然后您将看到完整的错误消息,这将允许您调试。@ShadowWizard,但随后您将向公众显示可能敏感的后端代码摘录。正确的异常处理或事件查看器将显示真正的错误消息event viewer>windows logs>application@RickS默认情况下,所有未处理的异常都会出现在事件查看器中。i获取的编译错误“the name”WriteTo_error_TXT_File”在当前上下文中不存在。这也可能是编译器错误。那么这段代码就不起作用了。@user1666620-错误日志将在哪里创建?@user2676140,如应用程序中的注释所示。\u error.“这个函数是用户定义的方法…”这意味着我们需要手动为它编写单独的方法…但不用担心,我也为它添加了代码。在我的编辑中,请检查它。。。
void Application_Error(object sender, EventArgs ex) 
    { 
        Exception e = Server.GetLastError().GetBaseException();
            if (!e.Message.ToUpper().Contains("FILE DOES NOT EXIST."))
            {
               //This function is user defined Method which accepts string as inpout and writes it to error.txt file with date and time.
               WriteTo_ERROR_TXT_File(e.ToString());                              

              //Redirect to custom error display page               
               Server.Transfer("Error.aspx");    
            }        

    }

public void WriteTo_ERROR_TXT_File(string inputString)
    {
        using (System.IO.StreamWriter file = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath("Error.txt"), true))
        {
            file.WriteLine(inputString);
        }

    }