惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Register - Security
The Register - Security
Cisco Talos Blog
Cisco Talos Blog
P
Proofpoint News Feed
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
V
Visual Studio Blog
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
博客园 - 叶小钗
V
Vulnerabilities – Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
IT之家
IT之家
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
罗磊的独立博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
V2EX - 技术
V2EX - 技术
T
The Blog of Author Tim Ferriss
小众软件
小众软件
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
DataBreaches.Net
L
LINUX DO - 热门话题
大猫的无限游戏
大猫的无限游戏
V
V2EX
Latest news
Latest news
NISL@THU
NISL@THU
Last Week in AI
Last Week in AI
Spread Privacy
Spread Privacy
云风的 BLOG
云风的 BLOG
S
Secure Thoughts
W
WeLiveSecurity
S
Security @ Cisco Blogs
C
CERT Recently Published Vulnerability Notes
AWS News Blog
AWS News Blog
I
InfoQ
A
About on SuperTechFans
K
Kaspersky official blog
Security Latest
Security Latest
P
Proofpoint News Feed

博客园 - JasonBie

使用NPOI编辑Excel C# datagridview 快速导出数据到Excel Outlook2016 不能自动配置企业Exchange的解决办法 Linq实现left join左连接 电脑端微信语音像机器人解决办法 解决sql server collation conflict Asp.net APP 重置密码的方式 jQuery dataTables 列不对齐的原因 JavaScript 获得客户端IP Entity Framework Linq 动态组合where条件 查询SQLSERVER执行过的SQL记录 Asp.net Web API 返回Json对象的两种方式 Read Excel file from C# JavaScript测试工具比较: QUnit, Jasmine, and Mocha MVC删除数据的方法 Session State Cookie Transferring Information Between Pages View State
Asp.net Form验证后造成URL参数重复的问题
JasonBie · 2012-11-29 · via 博客园 - JasonBie

开发Asp.net网站, 开发网站使用Form验证, 需要在Web.config中加入如下节点

    

<authentication mode="Forms">
      <forms loginUrl="~/Public/Login" timeout="30" />
    </authentication>


打开带有参数的页面时,如果未登录或登录已超时,会自动跳转到Login页面, 但是当输入完用户名密码后, 如果使用 this.HttpContext.Request.UrlReferrer 获取之前的页面就会发现获取到的Url中包含重复的参数列表.
至于为什么会出现重复,可以参考:
 http://blogs.msdn.com/b/vijaysk/archive/2008/01/24/anatomy-of-forms-authentication-return-url.aspx 

可以这样获得没有重复的Url:

var urlPathAndQuery = this.HttpContext.Request.UrlReferrer.PathAndQuery;
var returnUrlIndex = urlPathAndQuery.IndexOf("ReturnUrl=");
if (returnUrlIndex > -1)
{
    var parameterIndex = urlPathAndQuery.IndexOf("&");
    string returnUrl = parameterIndex == -1 ? urlPathAndQuery.Substring(returnUrlIndex + 10) : urlPathAndQuery.Substring(returnUrlIndex + 10, parameterIndex - (returnUrlIndex + 10));
    returnUrl = Server.UrlDecode(returnUrl);
    bool isNotLogoutUrl = returnUrl.IndexOf("Logout") == -1;
    if (isNotLogoutUrl)
    {
        return returnUrl;
    }
}