获取 ScriptHandlerFactory 处理程序

2024-01-18

有没有办法调用 System.Web.Script.Services.ScriptHandlerFactory 类的 GetHandler 方法,该方法返回 IHttpHandler 类型对象。我知道 ScriptHandlerFactory 是一个内部类,但是我可以通过其他方式获取它吗?我这么说的原因是因为我想路由我的 .asmx 路径并且路由需要这种类型的代码:

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
   return new WebServiceHandlerFactory().GetHandler(HttpContext.Current,
        "*",
        _VirtualPath,
        HttpContext.Current.Server.MapPath(_VirtualPath));
   }
}

上面使用了“WebServiceHandlerFactory”,但我只想使用 ScriptHandlerFactory,因为我也想使用 jquery ajax 调用。我将通过 jquery ajax 调用来调用 asmx 方法。你能帮我这样做吗?


借自Spring.Net。我用它来访问SimpleHttpHandler因为我使用 IoC 来创建HttpHandlers.

Edit: 这是代码 https://anonsvn.springframework.org/svn/spring-net/branches/nhibernate_configuration_schema/src/Spring/Spring.Web/Web/Support/AbstractHandlerFactory.cs我曾经想出如何去做。显然,它需要充分信任,而且我不喜欢这种 hack,但是 ASP.NET 并没有让我在创建自己的需要依赖内置功能的处理程序工厂时轻松执行 IoC。

Edit 2:将完全限定类型名称修复为System.Web.Services.Protocols.WebServiceHandlerFactory。修复了搜索中的程序集搜索IHttpHandler这是在System.Web to WebService这是在System.Web.Services。如果您有任何问题,请告诉我。

Edit 3:为此事道歉。我遗漏了SecurityCritical他们使用的类,如果你愿意,你可以用另一种方式来做,但我在做的时候直接从他们那里复制了。它用于提升和断言权限,这就是您需要的原因充分信任.

Code

    static YourCodeHere()
    {
        PrivilegedCommand cmd = new PrivilegedCommand();
        SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), new SecurityCritical.PrivilegedCallback(cmd.Execute));
        handlerFactory = cmd.Result;
    }

    private class PrivilegedCommand
    {
        public IHttpHandlerFactory Result = null;

        public void Execute()
        {
            Type handlerFactoryType = typeof(System.Web.Services.WebService).Assembly.GetType("System.Web.Services.Protocols.WebServiceHandlerFactory");
            Result = (IHttpHandlerFactory)Activator.CreateInstance(handlerFactoryType, true);
        }
    }

/// <summary>
/// Utility class to be used from within this assembly for executing security critical code 
/// NEVER EVER MAKE THIS PUBLIC!
/// </summary>
/// <author>Erich Eichinger</author>
internal class SecurityCritical
{
    internal delegate void PrivilegedCallback();

    [SecurityCritical, SecurityTreatAsSafe]
    [MethodImpl(MethodImplOptions.NoInlining)]
    internal static void ExecutePrivileged(IStackWalk permission, PrivilegedCallback callback)
    {
        permission.Assert();
        try
        {
            callback();
        }
        finally
        {
            CodeAccessPermission.RevertAssert();
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

获取 ScriptHandlerFactory 处理程序 的相关文章

随机推荐

  • 字典的匿名集合初始值设定项

    是否可以隐式声明 nextDictionary
  • 如何在 TensorFlow 中打印 Tensor 对象的值?

    我一直在使用 TensorFlow 中矩阵乘法的介绍性示例 matrix1 tf constant 3 3 matrix2 tf constant 2 2 product tf matmul matrix1 matrix2 当我打印产品时
  • 正确 Dafny 方法的 Z3 模型

    对于正确的方法 Z3能否找到该方法验证条件的模型 我原以为不会 但这里有一个例子 该方法是正确的 但验证发现了一个模型 这是 Dafny 1 9 7 的情况 Malte 所说的是正确的 我发现它也得到了很好的解释 Dafny 是健全的 因为
  • 图像属性的值 (C#)

    我正在尝试解决更改 Bitmap 对象的 ImageDescription 值的问题 添加文件的描述 搜索了相关主题 没有找到解决方案 My code public Bitmap ImageWithComment Bitmap image
  • 为什么我的 Cassandra 更新不起作用?

    我有以下 Cassandra 表 create table start stop id text start text end text price double PRIMARY KEY id start 我做了这样的插入 insert i
  • 在nodejs中获取url的响应(express/http)

    我试图在nodejs 中获取两个URL 的响应 但是http request 有问题 这是我到目前为止所拥有的 var url https www google com pretend this exists xml var opt hos
  • 样式组件中的CSS' calc() [重复]

    这个问题在这里已经有答案了 尝试这个 const styledDiv styled div props gt props takeViewportHeight min height calc 100vh 16px 它不起作用 我是否遗漏了样
  • 警告:mysql_query(): 3 不是有效的 MySQL-Link 资源

    我遇到了这个奇怪的错误 但我不知道它来自哪里 Warning mysql query 3 is not a valid MySQL Link resource in 3号怎么了 我不明白 有没有人自己经历过这个错误 PHP 使用资源作为特殊
  • 如何在 Android 模拟器中安装 APK 文件?

    我终于成功混淆了我的 Android 应用程序 现在我想通过安装来测试它APK http en wikipedia org wiki APK 28file format 29文件并在模拟器上运行 如何在 Android 模拟器上安装 APK
  • 无法在 macOS High Sierra 上构建和安装 Valgrind

    我无法在 macOS High Sierra 上安装 Valgrind 无法通过brew 我尝试过3 10 https github com msgpack msgpack c issues 525 After make install 我
  • R语言变量冲突

    我有一个 R 脚本 它采用 R 的其他脚本并以这种方式操作它们 并且还执行它们的代码 我的脚本使用一些变量 显然 当其他脚本使用公共变量名时 我会陷入混乱 我希望我可以像在胶囊中一样执行其他脚本 这样重合的变量就不会互相影响 我一直在阅读有
  • 将冷却/计时器添加到 on_message [Discord.py]

    我最近开始用 Python 制作一个 Discord 机器人 用它测试 Python 的基础 并自己创建了一个带有多个命令的功能机器人 为了扩大其用途 我添加了一个级别 XP 系统 到目前为止该系统正在运行 bot event async
  • Nexus 7 上不显示菜单按钮

    所以我很长时间都面临这个问题 我的 Nexus 4 和 Nexus 7 都运行 Android 4 3 并且我有 targetSdkVersion 11 的应用程序 我使用 11 因为任何低于 11 的目标 sdk 都不支持我的多点触控 问
  • IE 7 和 8 中的 CSS 倾斜转换

    我有菱形样式的菜单 它使用以下代码 它在 Chrome firefox ie9 等中运行良好 但我现在需要在 IE 7 和 8 中运行 有没有办法在这些旧版浏览器上执行此操作 http jsfiddle net C7e7U http jsf
  • Django 过滤外键字段

    简洁版本 我有一个用于食谱的 Django 应用程序 并且想要过滤要发送到我的视图中的模板的数据 我基本上希望特定用户添加的所有收据都作为上下文发送 以下过滤返回错误消息以 10 为基数的 int 的文字无效 我的用户名 recipes R
  • jquery旋转图像并将它们保存为同名文件(覆盖)?

    我有一个像这样的简单场景 我想旋转图像 并将它们保存为现有的旧文件 现在 所有功能都已完成 但是当我下载 保存图像时 它总是创建新的文件名 这是我的代码 div img src image a png alt div
  • Opencv 代码慢:有问题吗?

    这是我尝试改善图像颜色的函数 它有效 但真的很慢 也许有人有更好的主意 static Mat correctColor Mat AImage Mat copyImage AImage copyTo copyImage Mat imgLab
  • FileInputStream 和 FileOutputStream 在 Java 中如何工作?

    我正在阅读有关 java 中的所有输入 输出流的信息Java 教程文档 https docs oracle com javase tutorial essential io bytestreams html 教程作者使用这个例子 impor
  • 使用 EPPlus 设置下载位置

    我正在关注This http www c sharpcorner com Blogs 47619 export to excel using epplus aspxEPPlus 上的教程 但我对如何将下载位置设置为登录用户的 下载 文件夹感
  • 获取 ScriptHandlerFactory 处理程序

    有没有办法调用 System Web Script Services ScriptHandlerFactory 类的 GetHandler 方法 该方法返回 IHttpHandler 类型对象 我知道 ScriptHandlerFactor