iis .net clr_已解决:如何强制IIS加载特定版本的.NET CLR

iis .net clr_已解决:如何强制IIS加载特定版本的.NET CLR_第1张图片

iis .net clr

Micky McQuade turned me on to some code (from MSPSS) to solve my How to FORCE IIS to load a certain version of the CLR/.NET Framework. Greg Menounos also mentioned this solution in the comments.

Micky McQuade为我提供了一些代码(来自MSPSS)来解决我的“如何强制IIS加载特定版本的CLR / .NET Framework”。 Greg Menounos在评论中也提到了此解决方案。

PROBLEM: As discussed before, you can't use requiredRuntime or any .config changes (any that you ought to) to influence what version of the .NET Framework gets loaded into the IIS worker process. If you are using a .NET object as a COM object within Classic ASP, you'll always get the very latest .NET Framework installed on the machine. The values associated with the (fake) COM Object in the Registry are ignored. NOTE, this problem in with IIS/ASP/ASP.NET. If you're doing other things like calling .NET objects from VB6 Clients or something like that, you can always create a .exe.config and influence things with requiredRuntime like I talked about here.

问题:由于之前讨论的,你不能使用requiredRuntime或任何的.config变化(任何你应该)影响什么的.NET Framework的版本被加载到IIS工作进程。 如果将.NET对象用作Classic ASP中的COM对象,则始终会在计算机上安装最新的.NET Framework。 注册表中与(伪)COM对象关联的值将被忽略。 注意,IIS / ASP / ASP.NET中存在此问题。 如果要执行其他操作,例如从VB6客户端调用.NET对象或类似的操作,则可以始终创建.exe.config并使用我在此讨论过的requiredRuntime影响事物。

SOLUTION: The solution is a clever hack. What's the first opportunity to "jump in" and affect IIS? When the ISAPI Filters are loaded. Which ISAPI Filter method is called only once? Why GetFilterVersion(), in fact.

解决方案:解决方案是一个聪明的技巧。 “跳入”并影响IIS的第一个机会是什么? 加载ISAPI筛选器时。 哪个ISAPI筛选器方法仅被调用一次? 实际上为什么要使用GetFilterVersion()。

This is one of those 'slap your forehead' solutions because it makes sense when you hear it, but it sounds SO tedious when you come up with it and have to actually sully your nails with C++ again. Sigh, I coded in C++ for 8 years and now not only have I forgotten my ninja skills but I feel slightly dirty when I'm back in there. 

这是“拍额”解决方案之一,因为它在您听到时很有意义,但是当您提出来时却听起来很乏味,而实际上必须再次使用C ++钉住自己的指甲。 叹气,我用C ++编写代码已有8年了,现在不仅忘记了忍者技能,而且回到那里后感觉有点脏。

DISCLAIMER: This code of course assumes that there isn't some other higher-priority ISAPI filter doing crazy stuff in .NET. Unlikely, but worth mentioning. It's also totally unsupported, and you didn't get it here. In fact, you don't know where you got it. Who is this? What are you doing here? Move along, nothing to see here! No warranty expressed or implied as I didn't write it. Don't bug Micky or ask MS about it.  There's also no guarantee that this, or anything like this, is a solution for your problem(s).

免责声明:当然,此代码假定没有其他更高优先级的ISAPI筛选器在.NET中做疯狂的事情。 不太可能,但值得一提。 也完全不受支持,并且您在这里没有得到它。 实际上,您不知道从哪里得到的。 这是谁? 你在这里做什么? 继续前进,这里什么也看不到! 我没有写任何明示或暗示的担保。 不要打扰Micky或询问MS。 也不能保证这或类似的东西可以解决您的问题。

But it's interesting to read.

但这很有趣。

BOOL CNativeISAPIFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer){

BOOL CNativeISAPIFilter :: GetFilterVersion(PHTTP_FILTER_VERSION pVer){

    LPWSTR pszVer = L"v1.1.4322";

LPWSTR pszVer = L “ v1.1.4322” ;

    //or "svr" if you're on a multiproc box and you want the server GC in this process.

//或“ svr”(如果您位于multiproc框上,并且希望此过程中的服务器GC)。

    LPWSTR pszFlavor = L"wks";

LPWSTR pszFlavor = L “ wks” ;

    ICorRuntimeHost *pHost = NULL;

ICorRuntimeHost * pHost = NULL;

    HRESULT hr = CorBindToRuntimeEx(

HRESULT小时= CorBindToRuntimeEx(

        //version

//版

        pszVer,

pszVer,

        // svr or wks

// svr或wks

        pszFlavor,

pszFlavor,

        //domain-neutral"ness" and gc settings - see below.

// domain-neutral“ ness”和gc设置-参见下文。

        STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC,

STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC,

            CLSID_CorRuntimeHost,

CLSID_CorRuntimeHost,

        IID_ICorRuntimeHost,

IID_ICorRuntimeHost,

        (void **)&pHost);

( void **)&pHost);

    // Call default implementation for initialization

//调用默认实现进行初始化

    CHttpFilter::GetFilterVersion(pVer);

CHttpFilter :: GetFilterVersion(pVer);

    // Clear the flags set by base class

//清除基类设置的标志

    pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;

pVer-> dwFlags&=〜SF_NOTIFY_ORDER_MASK;

    // Set the flags we are interested in

//设置我们感兴趣的标志

    pVer->dwFlags |= SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT |           SF_NOTIFY_END_OF_NET_SESSION | SF_NOTIFY_END_OF_REQUEST;

pVer-> dwFlags | = SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT | SF_NOTIFY_END_OF_NET_SESSION | SF_NOTIFY_END_OF_REQUEST;

    // Set Priority

//设置优先级

    pVer->dwFlags |= SF_NOTIFY_ORDER_HIGH;

pVer-> dwFlags | = SF_NOTIFY_ORDER_HIGH;

    // Load description string

//加载描述字符串

    TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];

TCHAR sz [SF_MAX_FILTER_DESC_LEN + 1];

    ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),

ISAPIVERIFY(:: LoadString(AfxGetResourceHandle(),

    IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));

IDS_FILTER,sz,SF_MAX_FILTER_DESC_LEN));

    _tcscpy(pVer->lpszFilterDesc, sz);

_tcscpy(pVer-> lpszFilterDesc,sz);

    return TRUE;

返回TRUE;

}

}

File Attachment: NativeISAPI.zip (558 KB)

附件:NativeISAPI.zip(558 KB)

翻译自: https://www.hanselman.com/blog/solved-how-to-force-iis-to-load-a-certain-version-of-the-net-clr

iis .net clr

你可能感兴趣的:(c++,java,python,linux,javascript,ViewUI)