如何从外部访问控制器 [英] How to access a controller from outside

查看:116
本文介绍了如何从外部访问控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



感谢支持。我创建了一个Web API 2项目并在其中添加了一个控制器,并添加了几个带有HTTPGet属性的方法。如果我尝试从邮递员客户端访问该方法,它正常工作。但是,如果我试图从其他应用程序访问它们,我将遇到跨域原因问题。请帮我解决这个问题。



我尝试了什么:



我添加了config.EnableCors();在webapiconfig文件中。现在,我可以从外面访问api控制器。但是,控制器我添加了[EnableCors(*,*,*)]这个控制器的顶部。但是,它没有用。

解决方案

你看过这个吗?

ASP.NET核心中启用跨域请求(CORS) Microsoft Docs [ ^ ]

Hello everyone,

Thanks to support. I have created a Web API 2 Project and added a controller inside and added few methods with HTTPGet attributes. If i try to access that method from postman client it's working properly. But, If i tries to access them from other apps, I'm getting cross domain origin issue. Please help me to fix this issue.

What I have tried:

I have added config.EnableCors(); in webapiconfig file. Now, I can access api controllers from out side. But, Controllers i have added [EnableCors("*", "*", "*")] this one top of controller. But, It's not working.

解决方案

Have you had a look through this?
Enable Cross-Origin Requests (CORS) in ASP.NET Core | Microsoft Docs[^]


这篇关于如何从外部访问控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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