代码改变世界

ASP.NET MVC Url中参数过长引发的问题

2010-10-20 10:13  NicolasZhang  阅读(1158)  评论(1编辑  收藏  举报

今天使用ASP.NET MVC的时候需要给一个Action传递较长的参数类似:http://xx.xx.xx.xx/xxxxController/xxxAction/xxxx001$xxxx002$xxxx003$....,

IIS报错:The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

解决方法:

  1. 尽量避免传递长Url的情况;
  2. 在web.config中设置最大url length和querystring length:<httpRuntime maxQueryStringLength="2097151" maxUrlLength="2097151"/>;
  3. 把原来通过路由参数传递的字符串改用QueryString的方式传递,即将{controller}/{action}/id的方式改为{controller}/{action}?id=的方式。