asp.net - 在 IIS 上托管后从 Angular 调用时出现 WebAPI 错误(仅限 Post 方法)
问题描述
在调试模式下托管时,我的 ASP.NET WebAPI 调用运行良好(我可以从 angular、post man 等调用,没有发现问题)。
当我在 IIS 上托管相同的 WebAPI 并从 Angular 调用 post 方法时,它给了我一个错误(我对 get 方法没有任何问题)。即使从邮递员工具调用,Post 和 get 也能正常工作。
192.168.100.12:89/api/Booking/schedules/:1 加载资源失败:服务器响应状态为 404(未找到)
从源“http://localhost:3000”访问“http://192.168.100.12:89/api/Booking/schedules/”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
解决方案
You are trying to access the url at 192.168.100.12 from localhost:3000. Since they are not at the same address, it is considered cross-origin. By default these requests are blocked as a security measure.
- If you are using Angular (not angularjs), you can set up a proxy to forward requests during development. See this question for setting up a proxy.
- Alternatively, you can add a DEBUG flag that will disable your CORS policy.
推荐阅读
- bash - 在 Bash 中连接文件
- ios - 如何让画外音拼出单词中的每个字母?
- php - 在 WooCommerce 中仅获取有关产品查询的特定数据
- laravel - 如何预渲染我的 laravel+vue 应用程序的子集?
- android - 如何使用 Kotlin 在所有活动中播放背景音乐?
- android - 在 Unity3D 中安装引荐来源网址
- typescript - 如何简化“expect(typeof x).toBe(typeof new Class)”
- mysql - 需要帮助创建代码以查询多个表并返回总和等于查询的行
- .htaccess - 没有 FollowSymLinks 或 SymLinksIfOwnersMatch 的 RewriteRule
- javascript - 在自定义 React 钩子中返回函数时遇到问题