MVC4应用程序面向.NET 4.0,但似乎需要.NET 4.5运行 [英] MVC4 App Targets .NET 4.0 but seems to Require .NET 4.5 to Run

查看:186
本文介绍了MVC4应用程序面向.NET 4.0,但似乎需要.NET 4.5运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我在这里问一个问题 描述我是如何得到这个结论来了。我环顾各地的网络,并已发现给我的答案,或者让我足够接近,我才能够使飞跃干脆把它类似的问题,但并非一体。我在Visual Studio 2012开发面向.NET 4.0框架作为我们的生产服务器的MVC 4应用程序不能presently升级到.NET 4.5。在VS 2012和我的本地IIS应用程序完美运行。然而,当我部署它给我们的临时服务器,它只有.NET 4.0,它不会完全耗尽,虽然它显示登录页面。它不会,但是,显示注册或忘记了登录页面。

东西我曾尝试:


  1. 运行ASPNET_REGIIS.EXE -ir,虽然因为我们已经有4 ASP.NET应用程序的运行,没有必要 - [绝望]

  2. 拆卸和在web.config中添加,UrlRoutingModule-4.0

  3. 并确保所有dll的目标.NET 4.0

  4. ...当我回到明天上班会列出多个

在我的不断努力排除故障,我能够确定用户登录并通过身份验证后,抛出的唯一错误是述明,它找不到它在错误的目录存在我的错误页面。这个补救后,只比我的帐户,登录方法出现错误,没有其它的可用信息显示错误页面。我还检查SQL Server和注意到,测试用户的LastLogon场正在更新其验证了我对SQL和EF5连接。在这一点上,我添加记录,并能确定用户实际上验证,但在BaseController的code这是负责路由身份验证的用户主页/索引页似乎从来没有解雇(见完整code 这里)。

用尽几个小时试图隔离故障code后,一时兴起,我安装了.NET 4.5临时服务器和你瞧,它的工作如预期。我能使用的东西,是用于.NET 4.5?我使用的唯一额外的插件是:


  • TwitterBootstrapMVC

  • Grid.MVC

  • 实体框架5.0

  • ...当我回到明天上班会列出多个

和其他几个jQuery插件,两者都不需要.NET 4.5。我会比AP preciative更多,如果有人能指导我到正确的道路,以帮助解决这一难题。我知道你们在这里,跟我一样,喜欢挑战。让我们来看看,如果任何人都可以这个搞清楚之前,我做。


  

的障碍物的唯一用途是要克服。所有这一切的障碍确实有勇敢的人,不是吓唬他们,而是要挑战他们。


 〜伍德罗·威尔逊


解决方案

OK,我发现了什么事错了。对于一些我的控制器,我需要一个额外的参数,我不希望使用查询字符串,所以我增加了一个额外的URL参数来我RouteConfig:

  routes.MapRoute(
    名称:默认,
    网址:{控制器} / {行动} / {ID} / {} XID
    默认:新{控制器=家,行动=索引,ID = UrlParameter.Optional,XID = UrlParameter.Optional}
);

还没有研究为什么会在4.5工作,而不是4.0,但是当我找到它,我将发布一个解释或者链接到这里的解释,以防有人发现自己在一个类似的咸菜多少时间。如果有人读关心就此阐述,请随意。

OK, so I asked a question here that describes how I have arrived at this conclusion. I have looked around the web and have found similar issues but not one that gives me the answer or that gets me close enough for me to be able to make the leap to pull it altogether. The MVC 4 application that I developed in Visual Studio 2012 targets the .NET 4.0 framework as our production server can not presently be upgraded to .NET 4.5. In VS 2012 and on my local IIS the application runs perfectly. However, when I deployed it to our staging server, which only had .NET 4.0, it would not run completely, although it did display the Login page. It would not, however, display the Register or the Forgot Login pages.

Things I have tried:

  1. running aspnet_regiis.exe -ir, although it was not necessary as we already have ASP.NET 4 apps running - [desperation]
  2. Removing and adding in web.config, UrlRoutingModule-4.0
  3. Ensured all dll's targeted .NET 4.0
  4. ... will list more when I return to work tomorrow

In my continued troubleshooting efforts, I was able to determine that after the user logged in and was authenticated, the only error that was thrown was one stating that it could not locate my error page which existed in the Error directory. After remedying this, it only displayed the error page with no other usable information other than that an error occurred in my Account-Login method. I also checked SQL Server and noticed that the test user's LastLogon field was being updated which verified my connection for SQL and EF5. At this point I added logging and was able to determine that the user was in fact authenticated but the code in the BaseController which was responsible for routing authenticated users to the Home/Index page never seemed to fire (see the full code here).

After exhausting several hours trying to isolate the faulty code, on a whim, I installed .NET 4.5 to the staging server and Lo and Behold, it worked as intended. Could I be using something that is intended for .NET 4.5? The only additional plugins I am using are:

  • TwitterBootstrapMVC
  • Grid.MVC
  • Entity Framework 5.0
  • ... will list more when I return to work tomorrow

and several other JQuery plugins, neither of which require .NET 4.5. I would be more than appreciative if someone could guide me onto the right path to help solve this challenge. I know you guys here, like me, love a challenge. Let's see if anyone can figure this one out before I do.

The only use of an obstacle is to be overcome. All that an obstacle does with brave men is, not to frighten them, but to challenge them.

                                                                      ~ Woodrow Wilson

解决方案

OK, I discovered what was going wrong. For some of my Controllers, I needed an additional parameter and I did not want to use QueryString so I added an additional url parameter to my RouteConfig:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}/{xid}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, xid = UrlParameter.Optional }
);

Haven't had much time to research why this would work in 4.5 and not 4.0 but when I find it, I will post an explanation or a link to an explanation here, just in case someone finds themselves in a similar pickle. And if anyone reading cares to expound on this, please feel free.

这篇关于MVC4应用程序面向.NET 4.0,但似乎需要.NET 4.5运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆