从javascript调用c#程序 [英] Call c# program from javascript
本文介绍了从javascript调用c#程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从javascript调用c#,我是c#的新手,所以我不知道从哪里开始..
i need to call c# from javascript, i'm new to c# so i can't figure out where to start..
这是我的javascript代码:
this is my javascript code:
<script type="text/javascript"> //Default.aspx
function runCsharp() {
$.ajax({
type: "POST",
url: '..../csharp', //here i'm lost
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert('it works');
},
error: function (e) {
alert('something went wrong');
}
});
}
</script>
推荐答案
您可以创建Windows服务,该服务将托管简单的Web服务器,该服务器将处理来自角度应用程序的"http"请求.
.Net核心具有一个Kestrel服务器,可以用于此目的,对于您的用例来说,这已经足够了.
不要忘记打开CORS政策.
You can create Windows Service, that will host simple Web Server that will process 'http' requests from angular app.
.Net core has a Kestrel server that can be used for this and for your use-case it will be quite enough.
Don't forget to turn CORS policy on.
这篇关于从javascript调用c#程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文