MVC4 App Targets .NET 4.0 but seems to Require .NET 4.5 to Run

房东的猫 提交于 2019-12-12 04:48:51

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/28598383/mvc4-app-targets-net-4-0-but-seems-to-require-net-4-5-to-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!