我在我的项目中实现了自定义错误功能,并且它在本地IIS上工作,但不在活服务器上工作。我已经使用Global.asax文件实现了此功能,并且在MVC中的自定义错误控制器中调用了我的自定义错误操作方法。我已经发布并运行本地IIS及其工作,但在实时服务器上运行。自定义错误页面不在活服务器上工作
我的Global.asax.cs文件
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
//do not register HandleErrorAttribute. use classic error handling mode
filters.Add(new HandleErrorAttribute());
}
protected void Application_Error(Object sender, EventArgs e)
{
LogException(Server.GetLastError());
CustomErrorsSection customErrorsSection = (CustomErrorsSection)ConfigurationManager.GetSection("system.web/customErrors");
string defaultRedirect = customErrorsSection.DefaultRedirect;
if (customErrorsSection.Mod e== CustomErrorsMode.On)
{
var ex = Server.GetLastError().GetBaseException();
Server.ClearError();
var routeData = new RouteData();
routeData.Values.Add("controller", "Common");
routeData.Values.Add("action", "CustomError");
if (ex is HttpException)
{
var httpException = (HttpException)ex;
var code = httpException.GetHttpCode();
routeData.Values.Add("status", code);
}
else
{
routeData.Values.Add("status", 500);
}
routeData.Values.Add("error", ex);
IController errorController = new Test.Controllers.CommonController();
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
}
}
我的自定义错误控制器及其操作方法
public ActionResult CustomError(int status, Exception error)
{
var model = new CustomErrorModel();
model.Code = status;
model.Description = Convert.ToString(error);
Response.StatusCode = status;
return View(model);
}
那么,应该怎么办?
我建议你提供一些代码让我们来看看.. –
我们可以看到一些码?你的web.config安装是否正确?你还没有给我们很多信息继续下去。 –
本地IIS和Live IIS的含义是什么?我认为你需要检查IIS配置。 –