Mixing MVC 1 and MVC 3 - asp.net-mvc

Is there a way to have a project use MVC1 in certain areas and use MVC3 in other areas?
I have some previous code written but I was thinking of using MVC 3 to add other features.
Thanks.

Have you tried just upgrading? What things do you need from MVC1 that you can't use in MVC3? There are breaking changes, but it's very likely that you won't run into any of them, or that you can upgrade those parts of your code to run the entire app on MVC3.

No, there is no way to mix ASP.NET MVC 1 and ASP.NET MVC 3 in the same ASP.NET application. And that's a good thing because you should never even attempt to do this. They should be in separate applications if migration is not an option for you at the moment.

As per my knowledge I think we can use MVC1 code by adding following code in web.config file.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Please correct if I am wrong.

Related

Using unity Asp.Net MVC bootstrapper

In my ASP.Net MVC 5 application using VS 2013, I am using Unity MVC bootstrapper [package id="Unity.Mvc"] which is in other dll. Not sure, which is not working.
The similar setup is working VS 2012 + ASp.Net MVC 4 application and same package.
Can some body help me in resolving this? Is unity bootstrap is compatible with Asp.Net MVC 5?
My bad. Thanks for the responses. It is something wrong with my setup. My output binary (dll) is not copying into the web project folder as I gave the folder path wrong while upgrading. One more issue I observed to resolve is system.Web.http binding is failing. So I need to have the bind attribute in my web.config file.
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" />
</assemblyBinding>`

Trying to use FxCop with repeatedly upgraded MVC

I am trying to use FxCop on a project that has been upgraded from MVC 1 through MVC 3. The first time I ran my project, it asked me to locate MVC 3 for it. Once I did, it continued on for a bit and then asked me to find MVC 1, which I find odd because I no longer have it installed on this machine and the website operates just fine. This is the message it is giving me:
In our Web.config file we have the following, which is created automatically when you upgrade versions of MVC:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
Does anyone have any idea how to get rid of this error so FxCop will complete it's analysis of this project?
Got same problem with FxCop. Have you checked other assemblies, that might be dependant on MVC1? AFAIK MVC1 required 3 assemblies:
System.Web.Mvc
System.Web.Routing
System.Web.Abstractions
Maybe Routing or Abstractions left somewhere in your references?
As a workaround to get FxCop going you can update the FxCop configuration and set the following:
<appSettings>
<add key="AssemblyReferenceResolveMode" value="StrongNameIgnoringVersion" />
</appSettings>
Its most likely currently set to StrongName.
The allowable values are:
None - Do not match strong names at all, any assembly with the same file name is considered a match.
StrongName - Strong names including assembly name, version, culture and public key token must exactly match.
StrongNameIgnoringVersion - Strong names including assembly name, culture and public key token must exactly match. Assemblies with an equal or greater version are considered a match.`
However I would look at your assembly with something like DotPeek to try to determine why its still referencing the older version.

Authenticate action unreachable OpenId ASP.Net MVC4

I am following this example: OpenID Authentication with ASP.NET MVC3 , DotNetOpenAuth and OpenID-Selector
I started a new MVC4 project and add the OpenId code as suggested in the article above.
A break point on the Authenticate action in AccountController is unreachable.
Clicking on Google or Yahoo takes me to this blank page: http://localhost:37638/Account/Authenticate?ReturnUrl=
Shot in the dark: do you have appropriate bindingRedirects in your web.config file for MVC 1-3 to redirect to MVC 4?
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
An alternative to removing the Authorize attribute on the controller is to add the AllowAnonymous attribute to the action, that has fixed the issue for me.

Adding bindingRedirect element in web.config when upgrading from asp.net mvc 1 to asp.net mvc 2

I have got a question with regards to upgrading asp.net mvc applications from v1 to v2...
I've noticed in the ASP.NET MVC v2 Release notes that we need to add this code (please see below) when upgrading, but it did not state what would be the purpose of it because I've tried experimenting some of my apps to asp.net mvc 2 without adding this particular section in web.config.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Would there be implications should I not place this?
Thanks!
What this code does is pretty much tells your entire project that if there happen to be any old leftover references to MVC 1.0, then it should instead go try and use the 2.0 version instead. And I believe this would be inherited by class libraries as well where you might forget to update references.

Using MVCContrib's WindsorControllerFactory with new Windsor Castle 2.0

I'm trying to use WindsorControllerFactory (the latest 1.0.0.916 version) together with the new Windsor Castle 2.0 (again, the latest version). But I'm getting the
Could not load file or assembly
'Castle.Windsor, Version=1.0.3.0...
error when starting the Web application. Anyway, during writing of this question I managed to persuade the Web app to bind to new Castle's dlls by adding this block to the Web.config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Castle.Windsor" culture="neutral" publicKeyToken="407dd0808d44fbdc"/>
<bindingRedirect oldVersion="1.0.3.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Castle.Core" culture="neutral" publicKeyToken="407dd0808d44fbdc"/>
<bindingRedirect oldVersion="1.0.3.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Castle.MicroKernel" culture="neutral" publicKeyToken="407dd0808d44fbdc"/>
<bindingRedirect oldVersion="1.0.3.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
So I guess I answered my own question, but I wanted to share this with anybody having the same problem. Or is there a better way (apart from compiling the MVCContrib sources myself)?
I'd like to build MvcContrib myself too, and put its source along with our project code.
We use the same approach. There is one issue with the last available MvcContrib (v.2.0.96.0). It uses Castel.Windsor v.2.1.0.0 that is not compatible with the latest version of Castel.Windsor (2.5.1.0): AddComponentLifeStyle is obsolete. So you will have to change related MvcContrib code.
BTW, you can sign MvcContrib dlls without rebuilding them, for example with this tool: http://signer.codeplex.com/

Resources