Asp.net mvc - 确定哪个控制器请求页面? [英] Asp.net mvc - determining which controller requested page?

查看:70
本文介绍了Asp.net mvc - 确定哪个控制器请求页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候:



我目前正致力于构建ASP.NET MVC应用程序。我是.NET应用程序的新手,所以请原谅我的无知。



我使用Controller方法/动作(称为SetHeader())根据用户是否登录显示标题内的不同链接集。这可以正常工作,有两个例外 - 在用户登录和注销后立即生效。因此,我正在寻找一种方法,在SetHeader()操作中,确定用户是否通过我创建的登录和注销操作定向到当前页面。有什么好办法可以做到这一点?



非常感谢!



我是什么尝试过:



我试过Request.UrlReferrer.ToString();然而,结果并不完全是我所希望的。我只需要一种简单的方法来检查请求是否是由Login或Logout操作发出的。

Greetings:

I am presently working on building an ASP.NET MVC application. I am quite new to .NET applications so please forgive my ignorance.

I am using a Controller method/action (called SetHeader()) to display a different set of links within the header based upon whether a user is logged in or not. This works fine with two exceptions - right after the user logs and logs out. Therefore, I am looking for a way, within the SetHeader() action, to determine if the user is being directed to the current page by the Login and Logout actions I have created. What is a good way to accomplish this?

Thanks so much!

What I have tried:

I have tried Request.UrlReferrer.ToString(); however, the results were not exactly what I hoped for. I just need a simple way to check if the request was made by either the Login or Logout actions.

推荐答案

您应该能够从UrlReferrer获取请求者信息。如果没有看到您的代码,我们无法确定它无法正常工作的原因。您可以通过发布代码来改善您的问题,或者您可以尝试使用此链接中提供的替代方法:



重定向到ASP.NET MVC3中的调用者操作 - 堆栈溢出 [ ^ ]
You should be able to get the requester info from UrlReferrer. We cannot identify why it is not working without seeing your code. You can improve your question by posting your code or you can try alternate methods provided in this link:

Redirect to the Caller Action in ASP.NET MVC3 - Stack Overflow[^]


这篇关于Asp.net mvc - 确定哪个控制器请求页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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