gpt4 book ai didi

ASP.NET 通用处理程序在 .NET 3.5 到 .NET 4.0 升级后未被调用

转载 作者:行者123 更新时间:2023-12-04 04:48:40 26 4
gpt4 key购买 nike

这个旧标题描述了可见的问题,但新标题更好地描述了根本原因问题。我仍然不确定为什么 ASHX 没有被调用,所以我仍在寻找答案。我现在通过硬编码 API 描述符(Ext.app.REMOTING_API 变量)有一个解决方法。我从运行 .NET 3.5 的原始代码中,从 DirectProxy“provider”返回的变量中得到了那个 JSON 对象(Ext.app.REMOTING_API 变量)。我只是使用了一个在线 JavaScript 美化器让它看起来很漂亮(这样你就可以阅读它,而不是在一行上)。

旧标题:ExtJS 3 Ext.Direct proxy error: Uncaught TypeError: Cannot read property 'events' of undefined
我刚刚将 extdirect4dotnet 项目从 .NET 3.5 升级到 .NET 4.0。可以在此处找到该项目和示例项目 https://code.google.com/p/extdirect4dotnet/ .当我这样做时,我不得不在更改项目版本时临时复制 Web.Config 文件。我修复了由于继承 JSON.NET 中的类而导致的两个覆盖方法的参数列表,该类位于 http://json.codeplex.com/SourceControl/latest#readme.txt .我还修复了两个项目中 DLL 引用的方式。然后我将 Web.Config 中所有出现的“3.5”替换为“4.0”。

不幸的是,该项目使用 ExtJs 3.0.0,而不是 ExtJs 4.2.*,这是我正在使用此 .NET 服务器端堆栈 (extdirect4dotnet) 实现 Ext.Direct 代理的框架版本。所以它仍然使用一些旧的语法。下面我试图找出在 .NET 升级后如何修复特定错误。它仍在使用 ExtJs 3.0.0。请参阅“addProvider”函数中的“see this line”以查看它失败的行。当我从 JavaScript 调试它时,“provider”是未定义的。我猜它不知道如何获取提供者 Ext.app.REMOTING_API在我将其升级到 .NET 4.0 之后。

JavaScript 错误:

Uncaught TypeError: Cannot read property 'events' of undefined 

ExtJs 代码:
/*!
* Ext JS Library 3.0.0
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/

...
 * </code></pre>
* @param {Object/Array} provider Accepts either an Array of Provider descriptions (an instance
* or config object for a Provider) or any number of Provider descriptions as arguments. Each
* Provider description instructs Ext.Direct how to create client-side stub methods.
*/
addProvider : function(provider){
var a = arguments;
if(a.length > 1){
for(var i = 0, len = a.length; i < len; i++){
this.addProvider(a[i]);
}
return;
}

// if provider has not already been instantiated
if(!provider.events){ // <========================= see this line
provider = new Ext.Direct.PROVIDERS[provider.type](provider);
}
provider.id = provider.id || Ext.id();
this.providers[provider.id] = provider;

provider.on('data', this.onProviderData, this);
provider.on('exception', this.onProviderException, this);


if(!provider.isConnected()){
provider.connect();
}

return provider;
},

示例项目 JavaScript 代码:
Ext.Direct.addProvider(Ext.app.REMOTING_API); 

带有 .NET 3.5 实现的“提供者”对象上的 JavaScript 调试器的屏幕截图(在 .NET 升级之前)

(在新窗口中打开以查看大图)

enter image description here

作为一种解决方法,我对我的 js 文件执行了以下操作并对提供程序(Ext.app.REMOTING_API 变量)进行了硬编码。这本质上是一个 JSON 对象,它是我的 API 描述符。当示例项目使用 .NET 3.5 配置时,我从下面继承的 ASHX 代码中捕获了变量“provider”。出于某种奇怪的原因,我在 ASP.NET 中的通用处理程序没有被调用。 Generic Handler 继承的类对我来说似乎是普通的 .NET 4.0 Generic Handler (ASHX) 代码。我在下面粘贴了 HTML、ASHX 和继承的 ASHX。
Ext.onReady(function () {

Ext.app.REMOTING_API = {
"type": "remoting",
"id": "1",
"url": "../directRouter.ashx",
"actions": {
"CallTypes": [{
"name": "Echo",
"len": 1,
"formHandler": false
}, {
"name": "GetTime",
"len": 0,
"formHandler": false
}, {
"name": "UploadHttpRequestParam",
"len": 1,
"formHandler": true
}, {
"name": "UploadNamedParameter",
"len": 1,
"formHandler": true
}, {
"name": "SaveMethod",
"len": 3,
"formHandler": false
}, {
"name": "SaveMethod_Form",
"len": 1,
"formHandler": true
}, {
"name": "DateSample",
"len": 2,
"formHandler": false
}],
"TreeAction": [{
"name": "getChildNodes",
"len": 2,
"formHandler": false
}],
"CRUDSampleMethods": [{
"name": "create",
"len": 1,
"formHandler": false
}, {
"name": "read",
"len": 1,
"formHandler": false
}, {
"name": "update",
"len": 2,
"formHandler": false
}, {
"name": "destroy",
"len": 1,
"formHandler": false
}, {
"name": "reset",
"len": 0,
"formHandler": false
}]
}
};


Ext.Direct.addProvider(Ext.app.REMOTING_API);
//Ext.Direct.addProvider();

var Employee = Ext.data.Record.create([
{ name: 'firstname' }, // map the Record's "firstname" field to the row object's key of the same name
{name: 'job', mapping: 'occupation'} // map the Record's "job" field to the row object's "occupation" key
]);

var reader = new Ext.data.JsonReader({
totalProperty: 'results',
successProperty: 'success',
idProperty: 'id',
root: 'data'
}, [
{ name: 'id' },
{ name: 'email', allowBlank: false },
{ name: 'first', allowBlank: false },
{ name: 'last', allowBlank: false }
]
);
var writer = new Ext.data.JsonWriter({
returnJson: false,
writeAllFields: true
});

var store = new Ext.data.DirectStore({
api: {
read: CRUDSampleMethods.read,
create: CRUDSampleMethods.create,
update: CRUDSampleMethods.update,
destroy: CRUDSampleMethods.destroy
},
reader: reader,
baseParams: { dummy: 'blubb' },
writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
paramsAsHash: true,
batchSave: false,
batch: false,
prettyUrls: false,
remoteSort: true,
listeners: {
load: function (result) {
},
loadexception: function () {

},
scope: this
}
});
//

var myPageSize = 10;

var userColumns = [
{ header: "ID", width: 40, sortable: true, dataIndex: 'id' },
{ header: "Email", width: 100, sortable: true, dataIndex: 'email', editor: new Ext.form.TextField({}) },
{ header: "First", width: 50, sortable: true, dataIndex: 'first', editor: new Ext.form.TextField({}) },
{ header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: new Ext.form.TextField({}) }
];
Ext.onReady(function () {
Ext.QuickTips.init();

var userForm = new App.user.Form({
renderTo: 'user-form',
listeners: {
create: function (fpanel, data) { // <-- custom "create" event defined in App.user.Form class
var rec = new userGrid.store.recordType(data);
userGrid.store.insert(0, rec);
}
}
});

// create user.Grid instance (@see UserGrid.js)
var userGrid = new App.user.Grid({
renderTo: 'user-grid',
store: store,
columns: userColumns,
bbar: new Ext.PagingToolbar({
store: store, // grid and PagingToolbar using same store
displayInfo: true,
pageSize: myPageSize,
prependButtons: true,
items: [
'text 1'
]
}),
listeners: {
rowclick: function (g, index, ev) {
var rec = g.store.getAt(index);
userForm.loadRecord(rec);
},
destroy: function () {
userForm.getForm().reset();
}
}
});
setTimeout(function () {
Ext.get('loading').remove();
Ext.fly('loading-mask').fadeOut({
remove: true
});
store.load({ params: {
start: 0, // specify params for the first page load if using paging
limit: myPageSize,
foo: 'bar'
}
});

}, 250);
});

}); // onready

HTML 代码:

...
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css" />    
<script type="text/javascript" src="../ext/ext-base-debug.js"></script>
<script type="text/javascript" src="../ext/ext-all-debug.js"></script>
<!-- directProxy.rfc was registred in the web.config -->
<script type="text/javascript" src="../directProxy.ashx"></script>

...

ASHX:

使用系统;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using ExtDirect4DotNet;

namespace WebApplication1
{
/// <summary>
/// Zusammenfassungsbeschreibung für $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class directProxy : DirectProxy
{
public directProxy()
{
DirectProxy.routerUrl = "../directRouter.ashx";
}

}
}

在 ExtDirect4DotNet 中发现的继承 ASHX(在 .NET 4.0 升级期间代码没有改变):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Configuration;
using System.Web.Configuration;
using ExtDirect4DotNet;
using ExtDirect4DotNet.helper;

namespace ExtDirect4DotNet
{
/// <summary>
/// Represents the Proxy For Ext.Direct Comunication.
/// Tha ProccessRequest Methode scanns all the available Assembly for Classes and Methods with the
/// Direct Attribute.
/// </summary>
public class DirectProxy : IHttpHandler
{
private static string url = "";
public static string routerUrl {
get { return url; }
set { url = value; }
}

public static DirectProvider getDirectProviderCache(string apiNameSpace)
{

string routerUrl = (DirectProxy.routerUrl == "") ? ConfigurationCache.getRouterUrl() : DirectProxy.routerUrl;

// set default namspace for the remoting API
string apiNamespace = (apiNameSpace == null || apiNameSpace == "") ? "Ext.app.REMOTING_API" : apiNameSpace;


DirectProviderCache cache = DirectProviderCache.GetInstance();
DirectProvider provider;

//After being configured, the provider should be cached.
if (!cache.ContainsKey(apiNamespace + "/" + routerUrl))
{
provider = new DirectProvider(apiNamespace, routerUrl);
provider.Configure(AppDomain.CurrentDomain.GetAssemblies());
if (!cache.ContainsKey(apiNamespace + "/" + routerUrl))
cache.Add(apiNamespace + "/" + routerUrl, provider);
}
else
{
provider = cache[apiNamespace + "/" + routerUrl];
}
return provider;
}

public void ProcessRequest(HttpContext context)
{


// set default namspace for the remoting API
string apiNamespace = "Ext.app.REMOTING_API";
if (context.Request.Form["ns"] != null)
{
// if there is an namespace parameter, use it...
apiNamespace = context.Request.Form["ns"].ToString();
}
DirectProvider provider = getDirectProviderCache(apiNamespace);

context.Response.Write(provider.ToString());

/*
old code..


// set the Response typ to javascript since the responce gets Parsed into an Script Tag
context.Response.ContentType = "text/JavaScript";

string rem = "{";
rem += "url: \""+routerUrl+"\",";
rem += "type:\"remoting\",";


//string json = DirectProxyGenerator.generateDirectApi();
//rem += json;
rem += "};";

rem = apiNamespace + ".REMOTING_API =" + rem;
rem = "(function(){" + rem + "})();";

context.Response.Write(rem);
*/
}

public bool IsReusable
{
get { return false; }
}
}
}

最佳答案

在 IIS 7 中重现问题后,最终为 IIS 6 和 IIS 7 解决了这个问题!!

HTTP 处理程序在带有 .NET 3.5 和 .NET 4.0 的 IIS 6 上工作。但是,当您将框架升级到 .NET 4.0 时,IIS 7 上的 HTTP 处理程序会中断。为了修复,您必须做 4 件事。

1.) 将应用程序池 .NET 版本从 v2.0 更改为 v4.0

2.) 将应用程序池从集成更改为经典

3.) 将应用程序池从 64 位更改为 32 位

4.) 替换 Web.Config 中的 XML 标记。如果不这样做并且将这些行的“3.5.0.0”版本替换为“4.0.0.0”,则可能会损坏 IIS 并引发此错误。

Configuration file is not well-formed XML #2

.NET 3.5 版 Web.Config 配置:

(注意“PublicKeyToken”属性值中的小写字母与大写字母)

  <!--<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>-->

.NET 4.0 版 Web.Config 配置:
  <configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

相关:

https://serverfault.com/questions/525443/how-to-uninstall-iis-from-windows-server-2008/525496#525496

Configuration file is not well-formed XML #2

关于ASP.NET 通用处理程序在 .NET 3.5 到 .NET 4.0 升级后未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17779128/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com