在ASP.NET用户控件从重定向用户的地方回来 [英] Redirecting back from where user came from in ASP.NET User Control
问题描述
我有一个压倒一切的Page_Load方法的用户控件,但是我要的是,重定向从他们来自何处的用户是什么,它可以在ON init方法,或只要用户被重定向的任何方法。
这是我的时刻了,
公共部分类ASPUserControl:System.Web.UI.UserControl
{
保护无效的Page_Load(对象发件人,EventArgs的发送)
{ }
}
您可以使用的 UrlReferrer
乌里previousUri = Request.UrlReferrer;
如果(previousUri!= NULL)
Response.Redirect的(previousUri.ToString());
但是, UrlReferrer
只有当用户在链接上点击填充(通过FE 一项PostBackUrl
)或类似不,如果你已经使用的Response.Redirect
进入该页面。如果你已经使用 Server.Transfer的
你可以使用的 页。previousPage
,以便获得url。
I have a user control which overriding Page_load method, however what I want is, redirect user from where they came from, it can be on "ON INIT method" or any method as long as user is redirected.
This is what I got at the moment,
public partial class ASPUserControl: System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
You can use the UrlReferrer
Uri previousUri = Request.UrlReferrer;
if(previousUri != null)
Response.Redirect(previousUri.ToString());
However, the UrlReferrer
is only populated if the user clicked on a link(f.e. via PostBackUrl
) or similar, not if you've used Response.Redirect
to go to this page. If you've used Server.Transfer
you could use Page.PreviousPage
to get the url.
这篇关于在ASP.NET用户控件从重定向用户的地方回来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!