简体   繁体   English

成功登录后如何重定向到页面?

[英]How do I redirect to a page after successful login?

I'm fairly new to web forms development, playing around with a project created using the ASP.NET Web Application template in VS 2010. After the user successfully logs in, I want the user redirected to a page I created. 我是Web表单开发的新手,在VS 2010中使用ASP.NET Web应用程序模板创建的项目。在用户成功登录后,我希望用户重定向到我创建的页面。 How do I modify my project to redirect the user after login? 如何修改我的项目以在登录后重定向用户? Any samples / tutorials / etc are greatly appreciated. 任何样本/教程/等都非常感谢。

Thanks! 谢谢!

To simply redirect to a new page when your user has logged in, use the DestinationPageUrl property of your login control... assuming you're using the Login control that is. 要在用户登录时简单地重定向到新页面,请使用登录控件的DestinationPageUrl属性...假设您正在使用Login控件。

If you need to do anything more advanced you can use the OnLoggedIn event handler for your Login control to perform a redirect manually, or add any code for event logging and such. 如果您需要执行更高级的操作,可以使用Login控件的OnLoggedIn事件处理程序手动执行重定向,或者为事件日志记录添加任何代码等。

If you've rolled your own login control, and are just using things like text boxes and button controls, then in your Button_Click event, you can just use Response.Redirect("DestinationHere"); 如果你已经推出了自己的登录控件,并且只是使用文本框和按钮控件之类的东西,那么在你的Button_Click事件中,你可以只使用Response.Redirect("DestinationHere"); to take your users to a new page. 将您的用户带到新页面。

检查登录后:

Response.Redirect("url");
  <asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Admin/Default.aspx">
</asp:Login>

Go to Properties and Set DestinationPageUrl. 转到属性并设置DestinationPageUrl。

I assume you're using ASP.NET Login control. 我假设您正在使用ASP.NET登录控件。 There's a DestinationPageUrl property of that control that handles exactly that. 该控件的DestinationPageUrl属性可以完全处理该属性。 If login was successfull user is redirected to URL provided in that property. 如果登录成功,则用户将被重定向到该属性中提供的URL。

Server.Transfer( *url*) ?

(method on HttpServerUtility) (关于HttpServerUtility的方法)

I know next to nothing about ASP.NET, but from my Java web developer daze, redirect is bad because it involves another network round trip to the browser and back when you really just want to continue processing in another page. 我对ASP.NET几乎一无所知,但是从我的Java Web开发人员发呆,重定向很糟糕,因为它涉及到浏览器的另一个网络往返,当你真的只想继续在另一个页面处理时。

And Response.Redirect() really does issue a 302 response code ("try this other url instead") back to the browser. 并且Response.Redirect()确实会发出302响应代码(“尝试使用其他网址”)返回浏览器。 yuck. 呸。 XP XP

Server.Transfer() looks like the java version of Response.Forward() Server.Transfer()看起来像是Response.Forward()的java版本

对于Sharepoint场解决方案开发

Page.Response.Redirect("url");

The issue with Response.Redirect() is the 302. In some browsers (eg Chrome) this causes the new session cookie to be immediately invalidated. Response.Redirect()的问题是302.在某些浏览器(例如Chrome)中,这会导致新的会话cookie立即失效。

In other words, using that method to redirect causes the user to no longer be logged in, so you did not accomplish your purpose!. 换句话说,使用该方法重定向会导致用户不再登录,因此您无法实现目的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM