使用 iPhone UIWebView 时的 Asp.Net 表单身份验证 [英] Asp.Net Forms Authentication when using iPhone UIWebView

查看:36
本文介绍了使用 iPhone UIWebView 时的 Asp.Net 表单身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用表单身份验证的 Asp.net MVC 2 应用程序,目前我的 iPhone 应用程序在通过网络进行身份验证/登录方面遇到了问题.我们开发了一个使用 UIWebView 控件的简单 iPhone 应用程序.在这个阶段,应用程序所做的就是导航到我们的 Asp.Net 网站.很简单吧?问题是,用户无法通过登录页面.重现步骤是:

I am writing a Asp.net MVC 2 application that uses Forms Authentication and currently I am having a problem with our iPhone application in regards to the authentication/login over the web. We have developed a simple iPhone app that uses the the UIWebView control. At this stage, all the app does is navigate to our Asp.Net website. Simple, right? The problem is, that the user cannot get past the login page. The repro steps are:

  • 打开 iPhone 应用.
  • 应用导航到主页.
  • 用户未通过身份验证,因此他们被重定向到登录屏幕/页面
  • 用户输入正确的用户名和密码.点击提交.
  • 在服务器端,对用户进行身份验证并使用 FormsAuthentication.GetAuthCookie 生成 cookie 并发送到客户端.
  • 服务器发送重定向以将用户发送到正确的主页.

但是用户随后被重定向BACK到登录屏幕!

But the user is then redirected BACK to the login screen!

我已经对此进行了一些广泛的调试,我所知道的是:

I've done some extensive debugging on this and what I do know is:

cookie 正在发送到客户端,客户端正在存储 cookie.在 iPhone 调试器中验证了这一点,也通过使用 Javsascript 在页面上显示 cookie 数据进行了验证.cookie 正在被发送回服务器.在 Visual Studio 调试器中对此进行了验证.这是正确的 cookie(与设置的相同).属性 User.Identity.IsAuthenticated 出于某种原因返回 false,即使 auth cookie 包含在 Request 对象中.我已验证 iPhone 应用已设置为接受 cookie,并且它们在客户端上.

The cookie is being sent to the client, and the client is storing the cookie. Verified this in the iPhone debugger and also by using Javsascript to display cookie data on the page. The cookie is being sent back to the server. Verified this in the Visual Studio debugger. It is the correct cookie (it's the same one that was set). The property User.Identity.IsAuthenticated returns false for some reason, even though the auth cookie is contained in the Request object. I have verified that the iPhone app is setup to accept cookies, and they are on the client.

有趣的是:如果您在 iPhone 上打开 Safari 浏览器并直接访问我们的网站,则效果很好.

Here is the funny thing: It works fine if you open the Safari browser on the iPhone and go to our site directly.

它在 iPad 上也有相同的行为,因为它不会越过登录屏幕.这在模拟器和设备上重现.

It has the same behaviour on the iPad too in that it doesn't get past the login screen. This repros on the emulators, and on devices.

同一个网站已经过 IE 7-8、Safari(适用于 Windows)、Blackberry、IEMobile 6.5、Phone 7 的测试,并且可以找到.唯一不起作用的情况是 iPhone 应用程序中的 UIWebView.

This same web site has been tested with IE 7-8, Safari (for Windows), Blackberry, IEMobile 6.5, Phone 7 and it works find. The only circumstance that it doesn't work on is the UIWebView in the iPhone app.

推荐答案

我们找到的解决方案是创建一个文件 (generic.browser) 并包含此 xml 以告诉 Web 服务器Mozilla"和默认浏览器设置应该都支持cookies.

The solution we found was to create a file (generic.browser) and include this xml to tell the web server that "Mozilla" and the Default browser settings should all support cookies.

<browser refID="Mozilla" >
    <capabilities>
        <capability name="cookies"  value="true" />
    </capabilities>
</browser>

这篇关于使用 iPhone UIWebView 时的 Asp.Net 表单身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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