您好,我创建了一个Windows通用应用程序,其中使用的API托管在计算机的IP地址上.无论是从VS15还是从应用程序包运行应用程序,它都可以正常运行.但是,一旦我使用应用程序包在另一台计算机上运行此应用程序,它就无法正常工作.同样,如果我在另一台计算机的IP地址上托管相同的API,它将停止在我的计算机上工作.即使在两种情况下,我都可以通过点击浏览器中的URL路径来访问数据.但是在手机上运行应用程序包效果很好.
Hi I have created a windows universal app in which I am using API which is hosted on my machine's IP address. As I run the app whether from VS15 or from App package it works fine. But as soon as I run this app on another machine using app package it doesn't work. Similarly if I host the same API on another machine's IP address it stops working on my machine. Even though in both cases I can access the data via hitting the URL path in browser. But running the app package on phone works fine.
SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd.它显示此错误.
这是我的ajax调用示例:
Here is my ajax call sample:
var ajaxRequest = $.ajax({ url: apiAddress + "Conversation/Welcome" }); ajaxRequest.done(function (response, textStatus) { if (textStatus == 'success') { //success } else { //fail } });我的webapiconfig.cs
My webapiconfig.cs
public static void Register(HttpConfiguration config) { // Web API routes, configuration and services config.EnableCors(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); }我在类上方放置了 [EnableCors(origins:"*",标头:"*",方法:"*")] .
请帮助我.我在做什么错了?
Please help me. What I am doing wrong?
推荐答案清单中不允许进行私有网络访问.一旦我允许它运行正常.
Private Network Access was not allowed in Manifest. As soon as I have allowed that it worked fine.
更多推荐
Windows 10 Universal App中的托管API问题
发布评论