我现在有一个相当令人费解的方案,弄清楚如何将几个大型查询(每个查询的许多不同项目)集成到与基于C#的REST API进行通信的iOS应用程序中。我试图在应用程序中提取几个报告,如果我在API中重新创建所有这些查询以及在iOS中重新创建界面,则可能非常耗时。访问报告的页面是一个传统的ASP页面,并包含一个安全标头,以确保通过登录页面验证用户会话。有没有办法将其设置为UIWebView并以某种方式在加载UIWebView时验证会话?否则,这将是一个漫长而艰巨的过程。
在用户使用NSURLRequest登录到UIWebView后,cookie是否可能被转移?
每个页面都有代码来检查会话是否经过身份验证
<%
if Session("portallogin") <> "good" then
response.redirect("example.com")
end if
%>
以下是一些负责初始身份验证的相关登录代码
'Get the username and password sent as well as user ip
On Error resume next
Session("login") = "bad" 'init to bad
sent_username = Request("username")
sent_password = Request("password")
source = Request.form("source")
remember_me = Request("remember_me")
userip = Request.ServerVariables("REMOTE_ADDR")
sent_username = replace(sent_username,"'","'")
sent_username = protectval(sent_username)
sent_password = protectval(sent_password)
if rs.BOF and rs.EOF then
Session("login") = "bad"
response.cookies("user")("name") = ""
response.Cookies("user")("pword") = ""
else
arr = rs.GetRows()
password = arr(0,0)
memberid = arr(1,0)
expired = arr(2,0)
if sent_password = password then
Session("login") = "good"
if expired = "True" Then
%>
'''''''''''''''''''
if session is good
'''''''''''''''''''
Session("username") = sent_username
Session("maintuser") = sent_username
Session("b2buser") = sent_username
Session("password") = sent_password
Session("memberid") = memberid
Session("customernumber") = customernumber
Session("cno") = cno
Session("login") = "good"
if remember_me = "on" Then
response.cookies("entry")("doorway") = cook(sent_username)
response.Cookies("entry")("michael") = cook(sent_password)
response.Cookies("entry")("remember_me") = cook("CHECKED")
Response.Cookies("entry").Expires = Now() + 365
else
response.cookies("entry")("doorway") = ""
response.Cookies("entry")("michael") = ""
response.Cookies("entry")("remember_me") = ""
Response.Cookies("entry").Expires = Now() + 5
end if
答案 0 :(得分:1)
由于大多数参数引用了Request集合,因此您可以将参数放在查询字符串中,从而使它们成为UIWebView的基本URL的一部分。所以你的URL请求看起来像是
file.asp?username=xxx&password=yyy&source=zzz&remember_me=on
您需要将示例文件中的第7行更改为
source = Request("source")
但它仍适用于现有请求。
此代码的一个明显问题是您的应用中存储了用户名和密码,可能会被拦截和滥用。所以要注意这一点。我不推荐这种方法。
更好的解决方案是考虑重写登录函数以在数据库中存储临时GUID和时间戳,然后可以作为查询字符串的一部分在请求中传递。然后可以修改您的身份验证代码以检查该GUID是否有效并更新与GUID关联的时间戳(如果他们使用该页面的旧访问方法,则检查会话)。