[英]redirect after authentication is successful
When the user clicks on the paybill (secure page) option, he/she is prompted to log-in & then be redirected to the account page. 当用户单击“付款单”(安全页面)选项时,系统将提示他/她登录,然后将其重定向到帐户页面。 I am using
Page.ResolveUrl
in the Login_Authenticate
method. 我在
Login_Authenticate
方法中使用Page.ResolveUrl
。 Once logged in, if the user navigates to any different page on the website & then clicks on paybill again, I check the Identity.IsAuthenticated
status in the page load and depending on this I again redirect the user to the account page. 登录后,如果用户导航到网站上的任何其他页面,然后再次单击付款单,我将在页面加载中检查
Identity.IsAuthenticated
状态,并根据此状态再次将用户重定向到帐户页面。 I want to know if this is the right way or if there are any best practices for doing this as this involves a lot of server calls. 我想知道这是正确的方法还是执行此操作的最佳实践,因为这涉及大量服务器调用。 Can I do this functionality using the
LoggedInTemplate
in the asp:LoginView
or Javascript? 我能做到使用此功能
LoggedInTemplate
在asp:LoginView
或JavaScript? I have the code for your ref... 我有代码供您参考...
protected void Page_Load(object sender, EventArgs e)
{
//to directly link user to account if it's authenticated
var userauth = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
if (userauth)
{
string urlredirect = Page.ResolveUrl("~/" + SiteConfig.PageMappings["ACCOUNT"]);
Response.Redirect(urlredirect);
Server.TransferRequest(urlredirect);
}
}
You don't need to do both the Redirect and the TransferRequest. 您无需同时执行Redirect和TransferRequest。 Response.Redirect sends a 302 to the browser to tell it to access a new page.
Response.Redirect向浏览器发送一个302,通知浏览器访问新页面。 Server.TransferRequest causes the request to be handled in a different Page within the existing request.
Server.TransferRequest使请求在现有请求内的不同Page中进行处理。 If you're doing authentication, you likely want to scrap the current session and start over, which means just using Response.Redirect.
如果您要进行身份验证,则可能要废弃当前会话并重新开始,这意味着仅使用Response.Redirect。 I use Response.Redirect in circumstances like this.
我在这种情况下使用Response.Redirect。 I also think it's useful for the user to see they've been redirected to another page for login (as well as being useful for page caching and back/forth navigation in the browser. wrt to authentication and login).
我还认为对于用户来说,查看他们已重定向到另一个页面进行登录很有用(以及对浏览器中的页面缓存和后退/前进导航很有用。用于身份验证和登录)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.