I am unfamiliar with the way ASP.NET (using MVC) deals with .dll
files and would like to know why the following behavior occurs:
In both scenarios, there is a primary MVC application and a secondary MVC application (MyApps.Secondary
). And in both instances, the secondary application has hard coded view locations in the actions.
Scenario One
When I move the .dll
of the secondary application to my primary MVC application's bin
folder I can navigate to the controllers in the secondary application.
Scenario Two
If I move the .dll
of the secondary application to a different folder (called extras
) under my primary web application, I then have to do the following in order to easily navigate to one of the actions/controllers inside the secondary application via the primary web 开发者_如何学Capplication:
1- Add MyApps.Secondary
under the assemblies section of the compilation section
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="MyApps.Secondary"/>
2- Add the folder extras
(the folder where MyApps.Secondary
is located` in the probing element
<probing privatePath="bin;extras"/>
I guess my question is, why do both of these scenarios work and why do I need to do the extra work in scenario two?
An answer to this question about the compilation element states that <compilation><assemblies>
element is meant for compiling .cs
and .vb
files, but in both my scenarios, I don't have either type of files. Is it maybe used for compiling .aspx/.ascx
pages for the secondary application? If it is indeed compiling .aspx/.ascx
files, why do I not need to include the assembly in the first scenario?
You do actually have .cs and .vb files in your secondary application, however they have already been compiled into a .dll. Each controller file, model, partial class, repository, etc. are .cs or .vb files.
To answer your question regarding why you have to do extra work, .NET by default looks in the bin folder for assemblies to include when it builds an application for runtime (and some other places on the server itself, but that is not relevant to your question). If you want to include an assembly that is not in the bin folder, you have to tell it to a) register it using the fully qualified name and b) where the assembly is actually at.
Take a look at this link from the other answer on the referenced post, especially the last few paragraphs about the assemblies section of the web.config. It may help to add some clarity to this (and my ramblings) for you.
精彩评论