Reputation: 15197
I am trying to redirect to a view and keep getting the error posted in the question title.
During breakpoint testing the code passing though the first bit of code iv lay down below setting the message and setting the exception. after continuing after the return redirect the very next page displayed is as follows.
Adding break points to the ErrorController and error model i found that the code never gets there.
The view i'm trying to post to is an error page. Here is so code to help you see the problem.
The RedirectToAction:
string message;
message = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";
return RedirectToAction("Error", "Error", new { ex = ex.ToString(), message = message});
The action in my ErrorController:
public ActionResult Error(string ex, string message)
{
ViewBag.Message = "Error";
return View(new ErrorModel(ex, message));
}
My Error model:
namespace MvcResComm.Models
{
public class ErrorModel
{
public string ex { get; set; }
public string message { get; set; }
public ErrorModel(string ex, string message)
{
this.ex = ex;
this.message = message;
}
}
}
Upvotes: 16
Views: 41823
Reputation: 9614
this fixed my problem:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="9999"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>
Upvotes: 0
Reputation: 625
I fixed follow: It run Ok
<system.webServer>
<security>
<requestFiltering>
<alwaysAllowedQueryStrings>
<add queryString="maxQueryString" />
<add queryString="maxAllowedContentLength" />
<add queryString="maxUrl" />
</alwaysAllowedQueryStrings>
<requestLimits maxUrl="10999" maxQueryString="2097151" />
</requestFiltering>
</security>
</system.webServer>
And add
<system.web>
<httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
</system.web>
Upvotes: 0
Reputation: 2602
In you web.config
under the <system.web> <httpRuntime>
tags you can set your maxQueryStringLength
so its like
<system.web>
<httpRuntime maxQueryStringLength = "**MY NUMBER**" />
</system.web>
check out the msdn reference : http://msdn.microsoft.com/en-us/library/e1f13641%28v=vs.100%29.aspx
Also please increase maxQueryStringLength in the IIS configuration, check out :
http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits
Upvotes: 2
Reputation: 4572
In the root web.config
for your project, under the system.web
node:
<system.web>
<httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
...
In addition, I had to add this under the system.webServer
node or I got a security error for my long query strings:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="9999" />
</requestFiltering>
</security>
...
Upvotes: 26
Reputation: 15138
Why don't you use TempData
, it's meant to do stuff like this. So for example:
TempData["ErrorMessage"] = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";
Check this link.
EDIT
Pass your exception message like this:
TempData["Error"] = ex.Message();
TempData["ErrorMessage"] = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";
return RedirectToAction("Error", "Error");
Then just access it from your ErrorController
, something like:
public ActionResult Error(string ex, string message)
{
var error = (string)TempData["Error"];
// do other magic ...
}
Upvotes: 4
Reputation: 2590
There is a maxumum URL length value settable in the web.config file. This question has a similar problem ASP.NET MVC, Url Routing: Maximum Path (URL) Length
Upvotes: 1