我尝试使用IIS为.NET框架应用程序设置自定义错误(使用Visual Studio 2015构建,如果相关)。我们的服务器是Windows Server 2012 R2 。我已经看过其他堆栈溢出解决方案,但没有解决这个问题。我在我的web配置和服务器管理器功能设置中设置了自定义错误。自定义错误页面的路径(是一个静态html页面)在服务器管理器中为所有错误状态代码设置。以前的一些堆栈建议禁用python,所以我尝试过,但没有解决任何问题。我的网页配置如下所示:运行时错误:执行自定义错误页面时发生异常
<?xml version="1.0"?>
<!--other web config-->
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5"/>
<customErrors defaultRedirect="/Views/Home/customError.cshtml" mode="On"/>
<compilation debug="true"/>
</system.web>
<system.webServer>
<!--<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" subStatusCode="-1" responseMode="ExecuteURL" path="/Views/Home/customError.cshtml" />
</httpErrors>-->
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="Entities" connectionString="***" providerName="System.Data.EntityClient"/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0"/>
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
我没有在Web配置中看到任何重复的静态内容。我直接在应用程序的服务器管理器中添加了所有iis错误页面重定向。
当我在本地运行应用程序并尝试触发404错误时,出现运行时错误:处理请求时发生异常。此外,执行第一个异常的自定义错误页面时发生另一个异常。该请求已被终止。 当我通过服务器运行它(也试图触发404错误)时,它会加载到上一页。
我不确定如何去解决这个问题。任何见解都会很棒!谢谢!控制器的
相关部分:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using System.Net.Mail;
using BE.Models;
using BE.ViewModels;
namespace BE.Controllers
{
public class HomeController : Controller
{
private Entities db = new Entities();
// Uri Route: "~/Home"
// View Route: "/Views/Home/Index.cshtml"
public ActionResult Index()
{
return View();
}
// Route: "~/Home/customError"
// View Route: "/Views/Home/customError.cshtml"
public ActionResult customError()
{
return View();
}
public ActionResult About()
{
return View();
}
public ActionResult Contact()
{
return View();
}
public ActionResult Resources()
{
return View();
}
}
}
我还修改了的global.asax.cs的样子:
namespace BE
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
RouteTable.Routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
};
};
然而,这给了我生成错误。
您指向'.cshtml'文件而不是正确的HTML文件。也许这就是问题所在? – DavidG