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

本文关键字:用户 检测 asp net 重定向 | 更新日期: 2023-09-27 18:06:13

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

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

是否有简单的方法来做到这一点?

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

您可以获得用户名如下…

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....
    }
 }

对于事件,这取决于您的代码。我想你可以在page_load事件中做这样的事情,如果你有任何疑问,你应该检查ASP。NETlifecylce http://www.google.fr/search?sourceid=chrome& ie = UTF-8& q = asp.net +生命周期

顺便说一句,你可以使用Response。

非常直观

protected void Page_Load(object sender, EventArgs e)
    {
       string username = HttpContext.Current.User.Identity.Name.ToString();
       if (username == "someusername")
       {
          Response.Redirect("someaspxfile.aspx");
       }
    }

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

中选择数据