c# - 无法将类型为 'System.Web.Hosting.SimpleWorkerRequest' 的对象转换为类型 'System.Web.Hosting.IIS7WorkerRequest'

标签 c# visual-studio-2010 visual-studio-2013 migration

将我的解决方案从 VS2010 迁移到 VS2013 后,我收到 InvalidCastException。

在 VS2010 中一切正常,相同的代码在 VS2013 中出现以下错误:

An exception of type 'System.InvalidCastException' occurred in System.Web.dll but was not handled in user code

Additional information: Unable to cast object of type 'System.Web.Hosting.SimpleWorkerRequest' to type 'System.Web.Hosting.IIS7WorkerRequest'.

我不知道该怎么办,在互联网上找不到任何相关内容。

错误出现在下面这段代码的第5行:

public static void AuthenticateUser(String UserName, Int32 Minutes = 30, Boolean IsPersistent = true)
    {
        FormsAuthenticationTicket _ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddMinutes(Minutes), IsPersistent, String.Empty);
        FormsIdentity _id = new FormsIdentity(_ticket);
        var _roles = Roles.GetRolesForUser(UserName);
        HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(_id, _roles);
    }

最佳答案

从技术上讲,这不是答案。但它帮助我解决了我的问题。 因此,我与大家分享了这一点,希望这会在不久的将来避免让某些人头疼。

在 Visual Studio 2010 Professional 中,我使用特定端口 (4302) 使用 Visual Studio Development Server 运行我的项目。

在 Visual Studio 2013 社区版中,我在 IIS Express 上运行我的项目。 出于某种原因,我仍然不知道为什么,这导致我的软件将“IIS7WorkerRequest”转换为“SimpleWorkerRequest”对象。

在我切换到具有自定义虚拟目录的本地 IIS 服务器后,我的错误消失了。如果有人可以解释这一点,我很想知道为什么会这样。但是现在这解决了上面的问题。

关于c# - 无法将类型为 'System.Web.Hosting.SimpleWorkerRequest' 的对象转换为类型 'System.Web.Hosting.IIS7WorkerRequest',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30754537/

相关文章:

visual-studio-2013 - Windows身份验证在IIS Express中不起作用,使用Visual Studio 2013,Windows 8进行调试

c++ - 根据运行时决策组合不同的迭代器

c# - 如何通过 ilnumerics 获得 Moore-Penrose 广义逆

c# - word文档,如何在asp.net应用程序中正确编辑

c++ - 模板化重复类型错误

javascript - Chirpy 和 ASP.NET 4

c# - 调用Parallel.Foreach中的方法并将结果保存到线程安全列表中

c# - NHibernate 中的 StatelessSession 和 Session 有什么区别?

vb.net - 动画 GIF 不会停止循环 Winforms

c++ - Visual Studio 2013 强制将 64 DLL 文件转换为 32 位应用程序 - 如何解决此问题?