简体   繁体   English

在IIS中将bin绑定为虚拟目录会创建global.asax错误

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

I want to deploy an ASP.NET MVC application to an IIS server and have all its required resources imported via Virtual directories. 我想将ASP.NET MVC应用程序部署到IIS服务器,并通过虚拟目录导入其所有必需的资源。 This works fine with every other folder used in the application. 这与应用程序中使用的所有其他文件夹都可以正常工作。 EXCEPT the bin/ folder. 除了bin /文件夹。 If i try to Virtual-Directory the BIN folder then the application cannot start: 如果我尝试虚拟目录的BIN文件夹,则该应用程序无法启动:

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. 我们有一个ASP.NET MVC网站解决方案。 It is deployed for 2 customers on one of our servers. 它在我们的一台服务器上为2个客户部署。 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). (Web.config和root-config.js表示角度)。

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. c:\\ inetpub \\ wwwroot \\ curstomerA \\和c:\\ inetpub \\ wwwroot \\ curstomerB \\都是在IIS中创建的自己的网站。 they have different application pools and are bound to different subdomains: 它们具有不同的应用程序池,并绑定到不同的子域:

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

c:\\inetpub\\wwwroot\\curstomerB\\ => customerB.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? 现在我的问题是:为什么这不适用于BIN文件夹? 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 ) (注意:我已阅读https://www.iis.net/learn/get-started/planning-your-iis-architecture/understanding-sites-applications-and-virtual-directories-on-iis

Ok, after I read the link and related links that HG Sandhagen pointed out 好,在我阅读了HG Sandhagen指出的链接和相关链接之后

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. 它不能按预期方式工作,因为IIS使用虚拟目录将url与物理目录进行匹配,但是Web应用程序在web.config所在的主文件夹下的bin文件夹中查找dll(在物理目录中)。 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. 可以在web.config中更改搜索路径。指定程序集的位置,但是据我所知,这仅适用于子文件夹。

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. 因此bin文件夹现在正在使用此符号链接,而我使用的其他目录是虚拟IIS目录。

PS: I realize now the title of this stackoverflow topic should have been in a question format like: PS:我意识到现在这个stackoverflow主题的标题应该是这样的问题格式:

"Why can I not successfully bind 'bin\\' as a virtual directory in IIS?" “为什么不能在IIS中成功将'bin \\'绑定为虚拟目录?”

My apologies ;) 我很抱歉 ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM