我最近构建了一个MVC 5 Web站点作为前端原型,并使用个人帐户进行身份验证.我现在需要构建一个WebApi2后端,它将为这个网站以及一个iPhone应用程序和其他多个客户端提供服务.我对与MVC站点和WebApi的身份验证感到困惑.
我希望所有用户管理都通过WebApi(将使用令牌)进行,以便它与客户端无关,但我不知道如果没有我的Identity类,网站端的Cookie身份验证将如何工作.好像我将使用MVC站点和WebApi复制代码.我想为mvc网站使用cookie,为webapi使用oauth令牌.我是否需要创建另一个像IdentityProvider这样的项目来管理它?或者只使用MVC和WebApi项目来实现这一点.谢谢!
编辑:我对如何管理用户身份感到困惑,用户可以通过MVC站点和WebApi请求进行登录.我需要能够以统一的方式生成UserIdentity和声明,当我同时使用MVC个人帐户模板和WebApi2个人帐户身份验证模板时,我感到很困惑.我想在AWS托管的MongoDB实例中存储用户,声明等.
在iOS 9中我使用UISearchController并在UIViewController中显示其搜索栏,我第一次点击搜索栏时遇到了很多延迟,并尝试了我能想到的一切无济于事......下面是我的代码以及延迟发生的视频链接 - 模拟器和我的设备都会出现延迟.
func setupUI() {
self.view.backgroundColor = UIColor.whiteColor()
// Required to properly display searchbar within nav & tabbar controllers
self.extendedLayoutIncludesOpaqueBars = true // have tried setting this to false as well
self.definesPresentationContext = true
self.searchResultsController = AppDelegate.getViewController(ScheduleStoryboard.name, controllerName: ScheduleStoryboard.Identifiers.foodSearchResults) as? SearchResultsController
self.searchController = UISearchController(searchResultsController: searchResultsController)
self.searchController.searchResultsUpdater = self
self.searchController.delegate = self
self.searchController.dimsBackgroundDuringPresentation = true
self.searchController.searchBar.delegate = self
self.searchController.searchBar.placeholder = "Search foods..."
self.searchController.searchBar.setBackgroundImage(UIImage(named: "background-searchbar")?.resizableImageWithCapInsets(UIEdgeInsetsMake(0, 0, 0, 0)), forBarPosition: .Any, barMetrics: .Default)
self.searchController.searchBar.tintColor = UIColor.whiteColor()
self.searchController.searchBar.sizeToFit()
// this headerView does …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的UITabBarController中的一个选项卡中实现一个搜索栏,该选项卡是UINavigationController中的UITableViewController ...我正在关注Apple教程 - 我尝试了很多不同的选项,包括这里提到的答案
在UINavigationController中使用带有UITabBarController的UISearchController时,搜索栏会被切断
我尝试使用设置以下属性
self.definesPresentationContext = true
Run Code Online (Sandbox Code Playgroud)
要么
self.tabBarController?.definesPresentationContext = true
Run Code Online (Sandbox Code Playgroud)
这是我的代码(来自UITableViewController,包含UISearchBar):
/// Search controller to help us with filtering.
var searchController: UISearchController!
/// Secondary search results table view.
var resultsTableController: SearchResultsTableController!
override func viewDidLoad() {
super.viewDidLoad()
resultsTableController = SearchResultsTableController()
resultsTableController.tableView.delegate = self
searchController = UISearchController(searchResultsController: resultsTableController)
searchController.searchResultsUpdater = self
searchController.searchBar.sizeToFit()
self.tableView.tableHeaderView = searchController.searchBar
searchController.delegate = self
searchController.dimsBackgroundDuringPresentation = true
searchController.searchBar.delegate = self // so we can monitor text changes
self.definesPresentationContext = true
}
Run Code Online (Sandbox Code Playgroud)
这是搜索栏的图片:
在我的View Controller中,我使用名为Client的类进行网络调用.客户端基本上是Alamofire(AFNetworking)网络调用的包装器,所以我有保存(POST),get(GET)和删除(DELETE)方法.
每个视图控制器都有一个实例变量客户端,用户可以创建,编辑和删除对象,如下所示:
client.save(object) { error in
print(error)
}
client.delete(object)
Run Code Online (Sandbox Code Playgroud)
我想确保对于给定的客户端,不会同时删除/修改同一个对象.客户端可能有多个实例处理相同的用户可编辑对象.
我的想法是创建一个客户端的所有实例将用于排队请求的串行队列,但是我遇到了每个函数的闭包问题.我希望异步完成请求(以避免阻塞主线程)和Alamofire使用闭包,但我希望客户端将请求视为同步,以便按接收顺序执行它们并等待所有闭包完成后再继续下一个避免任何冲突的请求.
我的客户端保存方法如下所示:
dispatch_async(self.serialQueue) {
self.httpClient.post("url", object) { error in
// handle errors, maybe make another request, etc
}
}
Run Code Online (Sandbox Code Playgroud)
在客户端执行下一个请求之前,我将如何确保完成每个请求(及其闭包).我也需要能够支持链式请求(所以在一个闭包中我会再发一个请求).