ASP.NET:指导用户到登录页面,登录用户发送回页面最初请求后? [英] ASP.NET: directing user to login page, after login send user back to page requested originally?

查看:217
本文介绍了ASP.NET:指导用户到登录页面,登录用户发送回页面最初请求后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ASP.NET 3.5手动实现一个登录系统。基本上,负载,我想现场检查,看看用户对象是活动的,如果没有,比我想的登录页面出现。

I am trying to manually implement a login system in ASP.NET 3.5. Basically, on load, I would like the site to check and see if user object is active, if not, than I want the login page to appear.

用户成功登录后,我想用户能够访问他最初请求相同的页面。

After user has logged in successfully, I would like the user to be able to access the same page he has requested originally.

例如:


  1. 要用户请求:MyPage.aspx - 没有登录

  2. 出现登录页面,而不是MyPage.aspx

  3. 在成功的用户登录

  4. MyPage.aspx出现,而不是Default.aspx的例如:

直勾勾地看着System.Net命名空间中,我看到有一个HttpWebRequest类,它有一个HttpWebRequest.AllowAutoRedirect属性,但我不知道该如何将让我从登录页面了。

Peering at the System.Net namespace, I see that there is an "HttpWebRequest Class" which has a "HttpWebRequest.AllowAutoRedirect Property" but am unsure how that would get me back from the login page.

请注意:我知道在ASP.NET自动认证系统设置,但我想有对数据库的手动控制。

NOTE: I know there are automatic authentication systems setup in ASP.NET, but I would like to have manual control over the database.

- 托梅克

推荐答案

你可以做什么,如果你不希望真正使用内置的形式Authentcation是:

What you could do, if you don't want to actually use the built in Forms Authentcation is:

检查,如果用户希望从匿名用户隐藏在每个页面上进行身份验证。如果不进行身份验证,他们重定向到登录页面的查询字符串的URL。

Check if the user is authenticated on each page you want to hide from anonymous users. If they are not authenticated, redirect them to your login page with the URL in the query string.

if(!HttpContext.Current.User.Identity.IsAuthenticated) {
    Response.Redirect(~/login.aspx?redirect=this_page.aspx");
}

那么你的登录页面上,经过用户登录,检查查询字符串,看看是否有redirect参数。

Then on your login page, after a user logs in. Check the query string to see if there is a redirect parameter.

if(!String.IsNullorEmpty(Request.QueryString["redirect"]) {
  string url = ResolveClientURL(redirect);
  Response.Redirect(url);
}

当然,这是使用身份验证,在那里你可以拒绝某些目录的匿名访问,当你做到这一点,.NET将重定向到登录页面(这是在web.config中设置)都内置到.NET和包括您的登录页面上的RETURNURL = blahblah。

Of course this is all built into .NET using Authentication, where you can deny anonymous access to certain directories, and when you do that, .NET will redirect to your login page (which is set in the web.config) and will include a "ReturnURL=blahblah" on your login page.

只是一个供参考。

这篇关于ASP.NET:指导用户到登录页面,登录用户发送回页面最初请求后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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