gpt4 book ai didi

ios - ionic NTLM 身份验证 - IIS

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:54:31 24 4
gpt4 key购买 nike

我正在使用 Ionic 框架构建一个 iOS 移动应用程序。该应用程序将访问由使用集成 Windows 身份验证的 IIS 上托管的 ASP.NET 5 (MVC 6) 应用程序提供的 API。服务器已经有一个使用 AngularJS 客户端的 Web 界面。我一直在尝试从 Ionic/Angularjs Controller 中获取对服务器的 $http 调用,但没有成功通过 IIS 集成 Windows 身份验证(我已尝试在设备/模拟器和 ionic 服务上运行)。我总是收到 401 Unauthorized 错误。我尝试将 withCredentials 设置为 true 并在请求中传递用户名/密码,但没有成功。当我尝试从 iPhone(非 windows 环境)上的 safari 访问 API URL 时,我确实得到了浏览器身份验证弹出窗口,它成功地登录了我的 intranet windows 用户名密码。

我最初遇到了一些 CORS 问题,我已通过在服务器端添加 CORS 服务并允许所有来源来解决这些问题。我还有代理设置,以避免在使用 ionic 服务进行测试时出现 CORS 问题。以前有人做过这样的事吗?这是我的 Controller 代码:

angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope, $ionicModal, $http) {
$http.defaults.useXDomain = true;
$http.defaults.withCredentials = true;
// Form data for the login modal
$scope.loginData = {};
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
// Triggered in the login modal to close it
$scope.closeLogin = function() {
$scope.modal.hide();
};
// Open the login modal
$scope.login = function() {
$scope.modal.show();
};

// Perform the login action when the user submits the login form
$scope.doLogin = function() {
console.log('Doing login', $scope.loginData);
$http.post('http://localhost:8100/api/APIAccount/Login',{withCredentials:true})
.then(function(response)
{
console.log('success');
}, function(error) {
console.log('error');
});

};
});

最佳答案

经过几个小时的故障排除,就像设置 ASP.NET 5 CORS 服务以允许凭据一样简单。在 ConfigureServices 函数的 Startup.cs 文件中,我必须输入以下内容。希望这对将来的其他人有帮助。

services.AddCors(options => 
{
options.AddPolicy("AllowAllOrigins",
builder => builder.WithOrigins("http://<domainname>")
.AllowCredentials());
});

关于ios - ionic NTLM 身份验证 - IIS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35639691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com