Tags: belong, control, depending, event, javascript, loggedin, login, logs, net, pages, redirect, role, security, successfully, user
Using javascript in the LoggedIn event of the login control
On .Net » .Net Security
11,512 words with 4 Comments; publish: Sun, 06 Jan 2008 06:16:00 GMT; (10054.69, « »)
I am using a Login Control. After a user logs in, I am able to successfully redirect them to different pages depending on what role they belong to, using this code:protectedvoid Login1_LoggedIn(object sender,EventArgs e){ Login _loginControl = (Login)Login1;
string _username = _loginControl.UserName;
Response.Redirect("SecondaryPage.aspx");
http://net-security.itags.org/q_dotnet-security_39699.html
All Comments
Leave a comment...
- 4 Comments

Hi
Here some example about how to call javascript function from codebehind in ASP.NET, Hope it helps
http://www.codeproject.com/aspnet/Mayank_Gupta.asp
This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.#1; Sun, 06 Jan 2008 06:17:00 GMT

Hmm. I was aware of RegisterClientScriptBlock and RegisterStartupScript but don't think they will work for this scenario of redirecting users to new browser windows from the loggedin event.
I was hoping that someone with more familiarity with the login control (and the loggedin event) might be able to answer this question. Specifically why my Response.Write code doesn't work in the LoggedIn event when it works fine elsewhere. This might give me the clue I need to successfully redirect users to a new browser window with no toolbars or menubars after logging in.
#2; Sun, 06 Jan 2008 06:18:00 GMT

Hi
I use the code like this, after user login, page will post back and you can open window base on the IsAuthenticated property.
protected void Page_Load(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
base.RegisterClientScriptBlock("", "<script>window.open('TestPage.aspx','Test', 'width=500, height=600, menubar=no, toolbar=no, resizable=yes');</script>");
}
}
Hope it helps
#3; Sun, 06 Jan 2008 06:19:00 GMT

Thanks XiaoYong Dai. This worked. I was able to add some code to re-direct the user to a different page based on what role they are in, like this:
protected
void Page_Load(object sender,EventArgs e){
if (Request.IsAuthenticated){
string username = Context.User.Identity.Name;
if (Roles.IsUserInRole(username,"Primary")){
base.RegisterClientScriptBlock("","<script>window.open('PrimaryPage.aspx','Test', 'width=500, height=600, menubar=no, toolbar=no, resizable=yes');</script>");}
elseif (Roles.IsUserInRole(username,"Secondary")){
base.RegisterClientScriptBlock("","<script>window.open('SecondaryPage.aspx','Test', 'width=500, height=600, menubar=no, toolbar=no, resizable=yes');</script>");}
else
{
base.RegisterClientScriptBlock("","<script>window.open('UnauthorizedPage.aspx','Test', 'width=500, height=600, menubar=no, toolbar=no, resizable=yes');</script>");}
}
}
This code goes in the Page_Load event of the page that is specified in the DestinationPageURL attribute of the Login control. In my case, I made it the same page that contained the login control itself, but you can specify a different page. So it looks like I don't need to use the LoggedIn event after all.
Thanks again.
#4; Sun, 06 Jan 2008 06:20:00 GMT