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

推荐订阅源

雷峰网
雷峰网
Recorded Future
Recorded Future
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
GbyAI
GbyAI
IT之家
IT之家
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
S
SegmentFault 最新的问题
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
The Cloudflare Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
腾讯CDC
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
月光博客
月光博客
博客园_首页
C
Check Point Blog
宝玉的分享
宝玉的分享
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Security Latest
Security Latest
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
N
News and Events Feed by Topic
Y
Y Combinator Blog
U
Unit 42
The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
Jina AI
Jina AI

博客园 - 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;
    }
}