我在团队项目(MVC应用程序)中工作。在我进行更新后,应用程序开始提供HttpException“类型转换失败!”我不知道为什么。
代码:
public static class UrlHelper
{
private static System.Web.Mvc.UrlHelper _urlHelper;
public static System.Web.Mvc.UrlHelper GetFromContext()
{
if (_urlHelper == null)
{
if (HttpContext.Current == null)
{
throw new HttpException("Current httpcontext is null!");
}
if (!(HttpContext.Current.CurrentHandler is System.Web.Mvc.MvcHandler))
{
throw new HttpException("Type casting is failed!");
}
_urlHelper = new System.Web.Mvc.UrlHelper(((System.Web.Mvc.MvcHandler)HttpContext.Current.CurrentHandler).RequestContext);
}
return _urlHelper;
}
}
以下代码行中的错误ocorre和'System.Web.Mvc.dll'和'System.Web.Mvc.dll'中存在“类型'System.Web.Mvc.MvcHandler'”
if (!(HttpContext.Current.CurrentHandler is System.Web.Mvc.MvcHandler))
任何想法?
[编辑更多信息]
实用信息:
使用Microsoft .NET FrameWork,版本4.5.51650
使用System.Web,版本4.0.30319
使用MVC 5,版本5.1.0.0
答案 0 :(得分:0)
试试这个:
if (!(System.Web.HttpContext.Current.CurrentHandler is System.Web.Mvc.MvcHandler))
{
throw new HttpException("Type casting is failed!");
}
答案 1 :(得分:0)
问题出在web.config文件中。在他们看来,有些配置不对。正确完成所有配置后,问题就解决了。我不确切知道导致这个特定错误的原因,我只知道问题是web.config文件