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

推荐订阅源

博客园 - 聂微东
罗磊的独立博客
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
T
Tenable Blog
Help Net Security
Help Net Security
WordPress大学
WordPress大学
H
Heimdal Security Blog
SecWiki News
SecWiki News
V2EX - 技术
V2EX - 技术
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
T
Tailwind CSS Blog
L
LINUX DO - 热门话题
Scott Helme
Scott Helme
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
O
OpenAI News
Latest news
Latest news
月光博客
月光博客
L
LangChain Blog
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
I
InfoQ
T
Threat Research - Cisco Blogs
人人都是产品经理
人人都是产品经理
Forbes - Security
Forbes - Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园_首页
雷峰网
雷峰网
T
Tor Project blog
Security Archives - TechRepublic
Security Archives - TechRepublic
G
GRAHAM CLULEY
Project Zero
Project Zero
MyScale Blog
MyScale Blog
V
V2EX
Vercel News
Vercel News
F
Fortinet All Blogs
The Register - Security
The Register - Security
N
News and Events Feed by Topic
P
Palo Alto Networks Blog
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 司徒正美

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