[ASP.NET]更简单的方法:FormsAuthentication登录ReturnUrl使用绝对路径

转自:http://www.cnblogs.com/dudu/p/formsauthentication-returnurl-absoluteuri.html

[ASP.NET]更简单的方法:FormsAuthentication登录ReturnUrl使用绝对路径 

被这个问题困扰多年,今天终于找到了更简单的解决方法,分享一下。

问题场景

假设我们在i.cnblogs.com站点的web.config中对FormsAuthentication进行了如下的设置:

<authentication mode="Forms">
  <forms name=".cnblogs" loginUrl="https://passport.cnblogs.com/login.aspx" protection="All" path="/"/>
</authentication>

当我们访问一个需要登录后才能访问的URL时,比如:http://i.cnblogs.com/post/list,请求会被重定向至如下的地址:

https://passport.cnblogs.com/login.aspx?ReturnUrl=%2fpost%2flist

瞧!通过ReturnUrl查询参数传递给登录页面的是相对路径——这就是问题所在。由于访问的页面与登录页面不在同一个二级域名下,使用这个相对路径是Return不回来的。

问题的根源

posted on 2016-04-18 18:43  chengjunde  阅读(158)  评论(0)    收藏  举报

导航