上海好程序员
2019-02-07 13:20Asp.NET Core RedirectResult 是怎样实现页面跳转的?
首先我定义一个接口,行为是跳转
[ApiController]
public class DefaultController : ControllerBase
{
[HttpGet("view/{id}")]
public IActionResult View(int id)
{
return Redirect("/view?id=" + id);
}
}
然后我定义个页面view.cshtml
@page
@{
Layout = null;
var id = Request.QueryString.Value;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>view</title>
</head>
<body>
Id: @id
</body>
</html>
1、
我浏览器直接访问 http://localhost:1634/view/1
浏览器地址跳转到 http://localhost:1634/view?id=1
2、
我用postman访问 http://localhost:1634/view/1
拿到的是HTML代码
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>view</title>
</head>
<body>
Id: ?id=1
</body>
</html>
headers
Transfer-Encoding →chunked
Content-Type →text/html; charset=utf-8
Server →Kestrel
X-SourceFiles →=?UTF-8?B?RDpcU3ZuXHByb2plY3RzLWRvdC1uZXQtY29yZVxNaXJQdWJsaXNoXE1pclB1Ymxpc2hcdmlldw==?=
X-Powered-By →ASP.NET
Date →Thu, 07 Feb 2019 05:14:21 GMT
那么问题来了,既然代码中没有javascript.location.href=也没有meta.refresh.url=浏览器是怎么实现的地址重定位?
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- asp.net core如何跳转404到指定的静态页面?
- vue.js
- c#
- asp.net
- 1个回答
- asp.net core 3.0 新手问题:使用“Scaffold identity”创建了注册登录页面后,如何快速的创建角色“Role“分配功能。
- visual studio
- c#
- asp.net
- microsoft
- 2个回答
- asp.net中怎样实现点击左侧菜单,右侧显示相应内容?
- visual studio
- c#
- sql
- asp.net
- 2个回答
- ASP.NET MVC5如何搜索数字区间?
- visual studio
- asp.net
- 2个回答
- ASP.NET MVC项目中如何实现点击按钮或者ActionLink弹出新窗口
- visual studio
- asp.net
- 1个回答
换一换