码迷,mamicode.com
首页 > Web开发 > 详细

Url.IsLocalUrl

时间:2015-01-07 18:16:33      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

问题:

Url.IsLocalUrl(returnUrl) 一直为false

解决方法:

url.islocalurl可以防止跳转攻击

页面之间传值,post过来一个参数,例如http://localhost:3221/Account/LogOn?returnUrl=/HealthDisplay/HistoryTrace

记住 这种判断 是针对于mvc route 例如这种方式/HealthDisplay/HistoryTrace  若为http://baidu.com这无法判断

故有这种判断方式 if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))更为复杂。

Url.IsLocalUrl

标签:

原文地址:http://www.cnblogs.com/wangjiachen/p/4208783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!