关于特定用户检测asp.net的重定向页面

时间:2011-08-19 16:18:20

标签: c# asp.net

我想如何在asp.net中实现以下内容:

我有Windows身份验证,我希望服务器检测用户是谁,并根据页面上的用户名重定向页面。

有一种简单的方法吗?

4 个答案:

答案 0 :(得分:1)

您可以获得像...这样的用户名。

string username = HttpContext.Current.User.Identity.Name.ToString();

获得用户名后,您可以将页面重定向到特定页面。

修改:您可以在Application_AuthenticateRequest事件中执行此操作,即Global.asax文件

 protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    if (Request.IsAuthenticated)
    {
      // put code here....
    }
 }

答案 1 :(得分:1)

对于事件,它取决于您的代码。 如果你有任何疑问你应该检查ASP.NETlifecylce http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=asp.net+lifecycle

顺便说一句,您可以使用Response.redirect重定向用户。

答案 2 :(得分:1)

非常简单

protected void Page_Load(object sender, EventArgs e)
    {
       string username = HttpContext.Current.User.Identity.Name.ToString();

       if (username == "someusername")
       {
          Response.Redirect("someaspxfile.aspx");
       }
    }

答案 3 :(得分:1)

如果您正在寻找带有用户名的控件,它将在请求中提供。您可以从请求中选择数据

相关问题