如何构建跨域HTML应用程序 [英] How do I build a cross domain HTML application

查看:60
本文介绍了如何构建跨域HTML应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,你的服务器可以是IIS,Linux等,客户端将是纯HTML,那么如何实现与这些服务器的跨域通信(获取数据并将数据发布到服务器)维护会话为好?使用angualr js,jquery等(在特定平台上没有依赖,即java,.net)



比方说,

数据A将来自服务器

数据B将来自B服务器等。



我尝试过:



我尝试过实现WCF ReST服务,该服务以JSON的形式发出数据,认为没有。客户端将消耗JSON数据,这将满足我的要求

解决方案

由于客户端是HTML,您只需要关注服务器...

关键字是​​'CORS' [ ^ ]

有一个关于如何创建支持跨源请求的Web API应用程序(可以从HTML轻松使用)的好文章:在ASP.NET Web API 2中启用跨源请求ASP.NET站点 [ ^ ]

现在可以轻松移植到.NET Core并托管在Linux上......

使用ASP.NET Core MVC和Visual Studio构建您的第一个Web API Microsoft Docs [ ^ ]

Hi, I have one requirement where your server can be IIS, Linux etc and client will be pure html so how can you achieve the cross domain communication with these server(getting data and posting data to the server) maintaining a session as well? using angualr js ,jquery etc (No dependency in particular platform i.e java, .net)

Let say,
Data A will be from A Server
Data B will be from B Server etc.

What I have tried:

I have tried of implementing WCF ReST service which emits the data in the form of JSON thinking that the no. of clients will be consuming the JSON data is this will suffice my requirement

解决方案

As the client is HTML you only have to focus on the server...
The keyword is 'CORS'[^]
There is a nice article on how to create a Web API application (that can be easily used from HTML) that enables cross origin requests: Enabling Cross-Origin Requests in ASP.NET Web API 2 | The ASP.NET Site[^]
Now this can be easily ported to .NET Core and hosted on Linux too...
Building Your First Web API with ASP.NET Core MVC and Visual Studio | Microsoft Docs[^]


这篇关于如何构建跨域HTML应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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