前言
最近做一个有关用户认证及授权的项目,可以使用不同的的认证方式(传统的用户名/密码、域用户、Facebook用户和Windows Live用户),单点登录到应用程序中。
用到的技术是微软的Claims 3.5,兼及WCF,证书,Asp.net, Windows Forms, 活动目录,AD FS2.0, OAuth 2.0等。
目前架构设计及原型论证的工作已经结束, 准备对其中碰到的一些问题和解决方案写出来。一方面作为备份笔记、另一方面也希望对从事这方面开发的园友碰到类似问题时时有些帮助。
读者对象
理解Claims基本概念,并从事基于Claims认证和授权应用程序开发的人员。
ID3206错误
错误原因:
在Relying Party应用程序为Asp.net程序时,如果请求认证的url和配置文件中的audienceUris值不匹配时,就会出现这个错误。
错误现象:
例如,我一个MetroMonitro的Asp.net应用程序;部署方式为IIS7中虚拟目录.
a) Web.config中配置如下:
![Claims系列 - ID3206错误 (A signin response may only redirect within the current web application: (url) is not allowed)_第1张图片](http://img.e-com-net.com/image/product/38d68f6c8e9d477280dd80a329b10cf7.png)
b)在浏览器中键入"http://cnxa1er-l0813.emrsn.org/MetroMonitor"(注意没有结束的斜杠)
c)敲回车键;进入认证方式选择页面;
![Claims系列 - ID3206错误 (A signin response may only redirect within the current web application: (url) is not allowed)_第2张图片](http://img.e-com-net.com/image/product/c519037d6a4a410080d654728a9e401f.png)
d)选择任意一种登录方式(此处为Windows Live)
![Claims系列 - ID3206错误 (A signin response may only redirect within the current web application: (url) is not allowed)_第3张图片](http://img.e-com-net.com/image/product/575b5962086a4039a5836934c471dd7a.jpg)
e)输入Windows Live帐号,并登录成功后出现错误:
![Claims系列 - ID3206错误 (A signin response may only redirect within the current web application: (url) is not allowed)_第4张图片](http://img.e-com-net.com/image/product/89a99e65b58c4b33a18a868ee61f8964.jpg)
解决方案:
由于请求的url比配置文件少了一个斜杆,因此只需要在每次请求时判断一个是否带有斜杆;没有的话,自动添加上就OK了。
具体实现如下:
a) 添加Global.asax文件(如果不存在的话);
b)在Application_BeginRequest事件添加如下代码:
1
public
class Global : System.Web.HttpApplication
2 {
3
4
private
void Application_BeginRequest(
object sender, EventArgs e)
5 {
6
//
workaround for "ID3206: A signin response may only redirect within the current web application: (url) is not allowed"
7
if (String.Compare(Request.Path, Request.ApplicationPath, StringComparison.InvariantCultureIgnoreCase) ==
0
8 && !(Request.Path.EndsWith(
"
/
")))
9 Response.Redirect(Request.Path +
"
/
");
10 }
11 }