请选择 进入手机版 | 继续访问电脑版

无忧编程_ASP.NET  / C# / PHP 程序员的软件世界

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 89|回复: 0

Request.Url.PathAndQuery和Request.UrlReferrer.PathAndQuery获取当前网页和来路网址

[复制链接]

262

主题

289

帖子

1172

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1172
发表于 2017-10-27 17:39:52 | 显示全部楼层 |阅读模式
Request.Url.PathAndQuery和Request.UrlReferrer.PathAndQuery获取当前网页和来路网址的本地化网址。
public ActionResult Ask(string id) {        if (!this.User.Identity.IsAuthenticated) {            string retUrl = Request.Url.AbsoluteUri;            return RedirectToAction("Login", "Account", new { returnUrl = retUrl });        }        ...   }
Since you did not provide us neither the Login action method nor RedirectToLocal method I am assuming you are using the AccountController from MVC5 template. If so
private ActionResult RedirectToLocal(string returnUrl){      if (Url.IsLocalUrl(returnUrl))      {        return Redirect(returnUrl);      }      return RedirectToAction("Index", "Home");}
You can see that RedirectToLocal method checkes if the returnUrl parameter is 'localUrl'. If not it does invoke Index. In your Ask method you are passing string retUrl = Request.Url.AbsoluteUrias returnUrl which is not local (starts with http://)!
Try string retUrl = Request.Url.PathAndQuery


Bingo. Using PathAndQuery worked.


内容来源:https://stackoverflow.com/questi ... -to-a-different-url

windows .net(C#+MSSQL) linux(php+mysql)  
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软件编程 Inc.  

GMT+8, 2017-12-17 11:58 , Processed in 0.163239 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表