IIS automatically making sub folders into applications, why? - c#

We have an Application that has lots of subfolders (each one compiled up in separate projects in VS as classes)
When you first load up the .sln file it is creating the virtual folders etc, but it is adding an application for each subfolder which prevents our code working. As it is expecting it to be one application so we have to go through the folders removing the applications added in error.
Each subfolder has a web.config that contains the configuration for the entityFramework and other required links, could this be why it is being added as an application?
in Summary:
Why are these applications being automatically added?
How can we stop them being added automatically?

Related

Is it possible to host a bin directory within an MVC application Areas folder?

I have an MVC 4 application that hosts other MVC applications within the Areas folder of the main application:
Web UI
Areas
Application 1
Content
Views
Application 2
Content
Views
Bin
MainApp.dll
Application1.dll
Application2.dll
Config
Views
Lib
Images
Other top level application folders
These applications share have their own set of dependencies which all currently reside in the main bin directory. This has caused us issues whereby one application requires a newer version of a package forcing me to upgrade the package within the second application. In my mind a resolution to this would be to isolate the dependencies by having a bin directory within each folder within the Areas folder which could contain the different versions of dependencies:
Web UI
Areas
Application 1
Bin
Application1.dll
DependencyV1.dll
Content
Views
Application 2
Bin
Application2.dll
DependencyV2.dll
Content
Views
Bin
MainApp.dll
Config
Views
Lib
Images
Other top level application folders
Aside from the risks of running multiple versions of dependencies - is this possible?
You can't do what you want to do.
If you have several apps in your areas, in term of project it's still a single app, so you only have one bin folder.
IIS may allow you to deploy several apps in Virtual directories, but you need to separate your areas (one VS project/csproj per app).
You deploy each app in a different folder, and in IIS you configure the website to the root app, and you right clic on it to add other applications

Can you have multiple APP_CODE folders in a project

I inherited this code from another developer (3rd party) but I am implementing it. Its a large website done in c#. For twitter integration they must have created a new website project because the code inside the sub folder has its own bin and app code folder. This is published on IIS but its a strange setup where it compiles at run time. (If I make a code change to a file on the webserver and save it, it updates instantly without having to publish).
This subdirectory is throwing a 500 error and I assume its because I dont believe you can have multiple bin and app_code in the same website project. Is that a correct assumption. Should I combinbe all the app_code directories to the one in the root? Here is a more visual example of the directory layout:
MyWebsite
App_Code
BIN
...other folders and files
MySubdirectory
App_Code (ALLOWED??)
BIN (ALLOWED??)
App_Code and Bin are special folders only at the root of the application. You should make MySubdirectory a child application in IIS.

Deploying multiple ASP.NET MVC application in a single Virtual directory

Normally an ASP.NET MVC application can be deployed by placing the application folder in the virtual Directory.
The application folder contains
bin folder
Scripts Folder(If needed)
Views folder
Global.asax file
web.config file
But, I want to place the bin folder outside the application folder so that I can deploy more applications in a single application folder. All applications share the bin folder and session also get shared.
What I want to do
..Virtual Directory
..\bin
..\App1Name\App1Contents
..\App2Name\App2Contents
..\App3Name\App3Contents
..web.config
I already achieved this for web application with web forms without Global.asax file. But in MVC application I am unable to shared the bin folder.
How to achieve it?
Where I need to place the Global.asax file?
How the route all the applications with bin folder placed outside the Applications?
Thanks in advance
This is not possible. You were able to achieve this with Web Forms because each individual page is in effect it's own application. However, MVC works differently. Many factors, not the least of which is the routing framework, requires that the web application be secluded. You cannot deploy multiple MVC applications to the same document root. You can deploy a second MVC application to a virtual directory within the first, but be advised that the web.config of the outermost application will affect the inner application as well.
Based on the fact that your applications are sharing common binaries already, you may want to look into using MVC Areas to facilitate a logical separation between applications (but have them all as part of a single application). The following link describes this in more detail: MVC Areas

.NET (Visual Studio) Share assets between projects

I'm working with Visual Studio. There I have a solution with several web-projects (.net MVC 4). All of these web-projects use the same javascript-libs. Currently I copied the library into each project, but this can't be the final solution. What is the best approach to share those library (assets in general) between all of the projects? Just link them? Or is it possible to create a project and reference it in all projects?
Update
"Link" the javascript files from another project is not a possible solution as I would have to link thousands of files (one of the libraries I am using is ExtJs) what makes it impossible to build a project without freezing visual studio...
Possible solution
Currently I have a (Web) MVC Project called "Web" and a (Class Library) Project called "ClientScript" which contains all the JavaScript files which are shared between several Web Projects. As linking all the needed JavaScript files is not a possible solution (because it's a matter of thousands of files what causes visual studio to freeze) I copy all the needed JavaScript files to the individual Projects using the Build Events in each Web Project (Project -> Properties -> Build Events -> Post-build).
My Post-build command line in the Web Project looks like this:
start xcopy "$(SolutionDir)ClientScript\Frontend\*" "$(SolutionDir)Web\Scripts" /r /s /i /y /D /E
Every time you build your Web Project all the changed Javascript files get copied from the ClientScript Project to your Web Project.
While developing the Javascripts I run a small "filewatcher" tool which automatically copies a file from the ClientScript Project to every Web Project when it changes. This way I don't have to build the Web Project every time when I make a change to one of the Javascripts.
Anyone that stumbles across this question here in the future should know that there are now Shared Projects in Visual Studio to solve this problem. Universal Windows projects use them by default and you can create your own by downloading and installing the VS extension here: https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450
Note: At this time they can be picky about what type of project you try to add the shared reference. I created a JavaScript shared project to share js files between a Windows store js app and an MVC web app and it would not let me do that saying they had to be of the same language. (It supports C#, C++, or JavaScript).
Place the JS files in a single folder, likely above all others, and add them to the project but use the "Link" option. It's part of the drop down on the "OK" button in the "Add existing item..." dialog.
When you run every new ASP.NET MVC 4 project it's take a new port then other app have take.
I simply suggest you a simple thing.
run a project which contain all the pacakages. open them webmatrix and run them as localhost:80.
You need to set the port in settings section of your site in webmatrix. Now it will rechable at localhost now you can reference all the libraries from this packages.
Slightly older thread, but I have another way of doing a similar thing using Web Essentials, that handles the issue of not publishing correctly.
I have a shared folder outside of the projects that require the shared file, normally a 'common' project with other things in as well, but can be just a simple folder as suggested by Michael Perrenoud.
However instead of 'Add as Link' I have been creating a new bundle in the project that requires the shared js/css file, with the same name as the shared file, and then referencing that file in the shared folder using a relative reference location rather than the root based one it starts with.
To add a file from a shared folder in the root of the solution to the scripts folder use the following code in a new bundle file (*.bundle), changing the folder/file names as required.
<?xml version="1.0" encoding="utf-8"?>
<bundle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://vswebessentials.com/schemas/v1/bundle.xsd">
<settings>
<minify>false</minify>
<runOnBuild>true</runOnBuild>
</settings>
<files>
<file>../../MySharedFolder/my-js-file.js</file>
</files>
</bundle>
Then every time you build it recreates the bundle with the latest version, this version is then also published as expected :)
You can even create a minified version if desired by changing 'minify' to true. Or better yet you can add them loads as a bundle too if you want, you have that flexibilty.
This is an older thread but due to complex business requirements these days applications are divided in to different modules or sub projects.Thus, brings us the need to share common resources like JavaScript files, themes and CSS style sheet files.
I personally feel that common files should be put in separate Asp .Net MVC 5 project which has following structure :ASP.NET MVC5 folder structure
Now the best part is you can separately manage the dependencies using Bower,NPM or Nuget package manager.
After you have organised all the files in this project host this project to your own CDN or may be on cloud. You can use Using CDN in Bundle Approach to get script or link references.
That will help you sharing common resources across all the projects.There us a short coming though if you have many developers on the team and if someone added incompatible version lib can affect all the apps.

How can I put files in the user's local application data folder in a setup project?

I'm working with a visual studio 2008 - You get access to a number of special folders to use if you want to include files within. One I don't see on the list is the user's local application data folder. Is there anyway to put files in that folder from within a VS2008 setup project?
When I was facing similar challenge, I made it so:
Created a class library auxiliary project.
Added the System.Configuration.Install.dll reference.
Added a new class inheriting from System.Configuration.Install.Installer
Wrote an override of the Install method to copy the files
In the Setup project, targeted the above mentioned project output to the Application folder and -
In Custom actions (Install group) picked the auxiliary project output from the Application folder.

Categories