在javascript中访问C#对象 [英] Access C# object in javascript

查看:87
本文介绍了在javascript中访问C#对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我创建了ActiveX控件,将文件转换为字节数组。

我正在使用我的activeX使用javascript的web应用程序。在IE8中,我能够获得文件的字节数组,但是在IE8之上,它在返回时给出了undefined。



我在下面发布我的javascript代码< br $>


Hi all,

I have created ActiveX Control that will convert file into bytes array.
I am consuming that activeX in my web application using javascript.In IE8 I am able to get byte array for the file but above IE8 it's giving undefined while returning.

I am posting my javascript code below

function CallFunction() {

            var obj = document.Adstringo;
            var filepath = document.getElementById("Fileupload1").value;            
            obj.Source = filepath;        
            var res = obj.GetFileBytes();  // Call ActiveX Function   
}





在res变量中我在IE版本大于8时未定义。在IE8中它正常工作。



我尝试过:



我尝试在activeX中更改函数的数据类型。





In res variable I am getting undefined in IE version greater than 8. In IE8 it is working properly.

What I have tried:

I have tried changing the data types for the function in activeX.

public object GetFileBytes()
        {
            FileStream fs = new FileStream(Source, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);
            br.Close();
            fs.Close();

            return bytes;
        }



我已经从对象更改为字节[]


I have changed from object to byte[]

推荐答案

ActiveX控件只会在Windows上的Internet Explorer中工作,并且仅当用户允许您的站点下载控件,并且脚本未标记为可安全执行脚本的ActiveX控件时才使用。



(你的控件是 NOT 标记为安全的脚本,是吗?因为它不是 - 它允许网站读取任何文件的内容用户的计算机,这绝对不是安全的。)



除非您正在创建一个内部内部网网站,否则您将控制所有网站对于将访问您网站的计算机,您应该不惜一切代价避免使用ActiveX控件。



原生文件API [ ^ ]在大多数浏览器中 [ ^ ],包括IE10及以上版本。

ActiveX controls will only work in Internet Explorer on Windows, and only if the user allows your site to download the control, and to script ActiveX controls not marked as "safe for scripting".

(Your control is NOT marked as "safe for scripting", is it? Because it's not - it allows a website to read the content of any file on the user's computer, and that is most definitely not "safe".)

Unless you're creating an internal "intranet" site, where you control all of the computers which will access your site, you should avoid using ActiveX controls at all costs.

There is a native file API[^] which works in most browsers[^], including IE10 and above.
function CallFunction() {
    var file = document.getElementById("Fileupload1").files[0];
    
    var reader = new FileReader();
    
    reader.onload = function(e){
        var fileBytes = e.target.result;
        // TODO: Do something with the data
    };
    
    reader.readAsArrayBuffer(file);
}



注意:截至2016年1月12日,只有支持的操作系统可用的最新版本的Internet Explorer才会收到技术支持和安全更新。桌面不再支持IE8。 IE9仅在Vista和Windows Server 2008/2008 R2上受支持。

生命周期支持策略常见问题 - Internet Explorer [ ^ ]


NB: As of 12th January 2016, only the most current version of Internet Explorer available for a supported operating system receives technical support and security updates. IE8 is no longer supported on the desktop. IE9 is only supported on Vista and Windows Server 2008 / 2008 R2.
Lifecycle support policy FAQ - Internet Explorer[^]


这篇关于在javascript中访问C#对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆