Binding bin as a virtual directory in IIS creates global.asax error

1.1k views Asked by At

I want to deploy an ASP.NET MVC application to an IIS server and have all its required resources imported via Virtual directories. This works fine with every other folder used in the application. EXCEPT the bin/ folder. If i try to Virtual-Directory the BIN folder then the application cannot start:

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load type 'MyCompany.Services.Global'.

Source Error: 


Line 1:  <%@ Application Codebehind="Global.asax.cs" Inherits="MyCompany.Services.Global" Language="C#" %>

Source File: /global.asax    Line: 1 

Now to the why-I-want-to-do-this:

I have following scenario in my company:

We have a ASP.NET MVC website solution. It is deployed for 2 customers on one of our servers. Both customers are always deployed at the same time. Both use the same version. But both of them use different configuration files. (Web.config & a root-config.js for angular).

structure would be like this

c:\inetpub\wwwroot\
                    + curstomerA\
                            + bin\
                            + Scripts\
                            + Views\
                            + (...)
                            + web.config
                            + root-config.js
                    + curstomerA\
                            + bin\
                            + Scripts\
                            + Views\
                            + (...)
                            + web.config
                            + root-config.js

both c:\inetpub\wwwroot\curstomerA\ and c:\inetpub\wwwroot\curstomerB\ are own websites created in IIS. they have different application pools and are bound to different subdomains:

c:\inetpub\wwwroot\curstomerA\ => customerA.myCompany.com

c:\inetpub\wwwroot\curstomerB\ => customerB.myCompany.com

so what i try to do is

c:\inetpub\wwwroot\
                    + curstomerA\
                            + bin\
                            + Scripts\
                            + Views\
                            + (...)
                            + web.config
                            + root-config.js
                    + curstomerA\
                            + <bin> as virtualDirectory onto c:\inetpub\wwwroot\curstomerA\bin\
                            + <Scripts> as virtualDirectory onto c:\inetpub\wwwroot\curstomerA\Scripts\
                            + <Views> as virtualDirectory onto c:\inetpub\wwwroot\curstomerA\Views\
                            + (...) [like above]
                            + web.config
                            + root-config.js

it cannot be an access rights problem; on a local machine i relaxed access rights to the folders and it still did not work.

now my question is: why does this not work with BIN folder? what do i need to do in order to make this work?

or do i just misunderstand for what Virtual Directories are used for? (NOTE: i have read https://www.iis.net/learn/get-started/planning-your-iis-architecture/understanding-sites-applications-and-virtual-directories-on-iis)

1

There are 1 answers

0
schmendrick On

Ok, after I read the link and related links that H.G. Sandhagen pointed out

It does not work as expected because the virtual directory is used by IIS to match url to physical directories, but the web application lookup for dlls (in physical directoris) in the bin folder below the main folder where web.config resides. There are possibilities to change the search path in web.config Specifying an Assembly's Location but as far as I know this works for subfolders only.

it does not seem possible because it seems to only work with subfolders. I therefore solved my issue by creating a directory junction.

So the bin folder is now using this symlink and the other directories I use are virtual IIS directories.

PS: I realize now the title of this stackoverflow topic should have been in a question format like:

"Why can I not successfully bind 'bin\' as a virtual directory in IIS?"

My apologies ;)