Reputation: 60741
i would like how to implement the following in asp.net:
i have windows authentication and i would like the server to detect who the user is and redirect the page depending on the username on the page.
is there an easy way to do this?
Upvotes: 0
Views: 261
Reputation: 52241
You can get the username like...
string username = HttpContext.Current.User.Identity.Name.ToString();
Once you have the username you can redirect the page to a specific page.
Edit: You can do it in Application_AuthenticateRequest
event, that is Global.asax
file
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
// put code here....
}
}
Upvotes: 1
Reputation: 6654
If you are looking for picking up the control with username in it, it will be available in the request. You can pick the data from request
Upvotes: 1
Reputation: 85
pretty straightforward
protected void Page_Load(object sender, EventArgs e)
{
string username = HttpContext.Current.User.Identity.Name.ToString();
if (username == "someusername")
{
Response.Redirect("someaspxfile.aspx");
}
}
Upvotes: 1
Reputation: 85
For event it depends of your code. i supose you could do such a thing in the page_load event if you have any doubt you should check the ASP.NETlifecylce http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=asp.net+lifecycle
BTW you can use Response.redirect to redirect the user.
Upvotes: 1