简体   繁体   English

从C#调用javascript函数(带有args)

[英]Call javascript function (with args) from c#

I have a WCF Service and I want to pass a SHA1 hashed string as a result. 我有WCF服务,因此要传递SHA1哈希字符串。

On the client side, I have a simple html page with javascript. 在客户端,我有一个带有javascript的简单html页面。

I have the code to make the SHA1 string in javascript and I want to use it for both client (dehash the message) and server (hash the message). 我有在JavaScript中制作SHA1字符串的代码,并且我想同时将其用于客户端(对消息进行哈希处理)和服务器(对消息进行哈希处理)。

The server is in C#. 服务器在C#中。

So, is it possible to call the SHA1 javascript function from C#? 因此,可以从C#调用SHA1 javascript函数吗?

This doesn't make sense for two reasons: 这是没有道理的,原因有两个:

1) You can't really share code between C# and JS, these languages are created for completely different purposes and are not interoperable, unless you are willing to allow code generation mess (like in ASP .NET Web Forms). 1)您不能真正在C#和JS之间共享代码,这些语言是为完全不同的目的而创建的,并且不能互操作,除非您愿意允许代码生成混乱(例如在ASP .NET Web窗体中)。 Still, this looks like abuse of DRY that hurts in the long run. 不过,从长远来看,这似乎对DRY的滥用会造成伤害。

2) SHA1 is one-way algorithm, there is no way to de-hash an encoded string (not talking rainbow tables here). 2)SHA1是一种单向算法,无法散列已编码的字符串(此处不讨论彩虹表 )。 You're using a wrong tool for the job. 您为该工作使用了错误的工具。

您可以在HTML页面上放置隐藏的控件,然后将哈希值放在该控件中,然后从C#访问该控件。

NO! 没有! But you can put the SHA1 result into an input and post it to server. 但是您可以将SHA1结果放入输入中并将其发布到服务器。

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

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