我收到此错误重定向 URI 不能包含换行符。当运行下面的代码时。正在工作MVC 4
。她的是我的工作代码。
protected void Application_Error(Object sender, System.EventArgs e)
{
System.Web.HttpContext context = HttpContext.Current;
System.Exception exception = Context.Server.GetLastError();
var stackTraceExcep = new StackTrace(exception, true); // create the stack trace
var stackTrace = stackTraceExcep.GetFrames() // get the frames
.Select(frame => new
{ // get the info
FileName = frame.GetFileName(),
LineNumber = frame.GetFileLineNumber(),
ColumnNumber = frame.GetFileColumnNumber(),
Method = frame.GetMethod(),
Class = frame.GetMethod().DeclaringType,
}).FirstOrDefault();
string FileName = stackTrace.FileName;
string LineNumber = stackTrace.LineNumber;
string ColumnNumber = stackTrace.ColumnNumber;
string MethodName = stackTrace.Method.Name;
string ClassName = stackTrace.Class.Name;
if (!string.IsNullOrEmpty(exception.Message))
{
Response.Redirect(String.Format("~/Error/{0}/?errorMessage={1},FileName={2},LineNumber={3},ColumnNumber={4},MethodName={5},ClassName={6}", "App_Error", exception.Message, FileName, LineNumber, ColumnNumber, MethodName, ClassName));//I got this error in this line
}
context.Server.ClearError();
}
什么问题 ?我们如何解决这个问题?我已经搜索并尝试了谷歌并得到了一些堆栈溢出的答案。但任何事情都对我没有帮助。
现在我该怎么办?
我的控制器操作方法
[HttpGet]
public ActionResult App_Error(string errorMessage, string fileName, string lineNumber, string columnNumber, string methodName, string className)
{
string errorNumber = Convert.ToString(errorRepository.AddError(errorMessage, fileName, Convert.ToInt32(lineNumber), Convert.ToInt32(columnNumber), methodName, className));
ViewData["message"] = "An error has occurred in the application . The error number is : " + errorNumber;
return View();
}