重定向到ASP.net核心中的url [英] redirect to url in ASP.net core

查看:113
本文介绍了重定向到ASP.net核心中的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,我一直在设法从VS 2017和asp.net Razor创建的program.cs文件中加载页面,但是我无法确定如何完成此工作,我在网上已经看到了找到答案,但是对于我的一生,我找不到任何可行的方法. 我想做的是在查找后我需要使用添加的搜索字符串再次加载页面,我拥有所有代码来进行查找和交叉检查,但是我无法使代码再次重定向到页面加上添加的搜索字符串.

I need some help I have been working on a way to load a page from within the program.cs file created by VS 2017 and asp.net Razor but I can not work out how this is done I have look on the web to find the answer but for the life of me, I cannot find anything that will work. What I'm looking to do is after a lookup I need to load the page again with an added searchstring, I have all the code doing the lookup and cross-checking but I'm unable to get the code to redirect to the page again with the added searchstring.

Response.Redirect("/machinery?MachineLocation=" + searchstring);

上面的代码不适用于program.cs或startup.cs,但可以用于任何cshtml.cs文件.

The above code will not work in program.cs or startup.cs but will work in any cshtml.cs file.

我尝试DI Httpcontext,但这一直返回null. 任何指针都很棒.

I have tried to DI the Httpcontext but this keeps returning null. any pointers would be great.

推荐答案

从控制器重定向到完整URL的方法很简单:

Redirecting from a controller to a full URL is done simply by:

return Redirect(stringFullUrl);

这篇关于重定向到ASP.net核心中的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆