?
Solved

response.redirect same page

Posted on 2010-09-21
10
Medium Priority
?
1,377 Views
Last Modified: 2012-05-10
if (!Page.IsPostBack)
            {
               

                if (!string.IsNullOrEmpty((string)Session["UserName"]))
                {

                    strVal = ((string)Session["UserName"]);

                    if (AuthenticateNTUsers(strVal) == true)
                    {
                        Response.Redirect("~/mypage.aspx", false);
                    }
                    else
                    {
                        Response.Redirect("~/login.aspx", false);
                       
                    }
                }
}
now when ever session is empty it is supposed to redirect to the login page and display the log in form, but for some reason its going into infinite loop. I guess because each redirect is not oseen as poast back. Any ideas as to how to resolve this?
0
Comment
Question by:Angela4eva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Author Comment

by:Angela4eva
ID: 33730866
above code is part of login.aspx page as well
0
 
LVL 10

Expert Comment

by:himanshut
ID: 33730979
if (!Page.IsPostBack)
            {
               

                if ((Session["UserName"].ToString()=="") || (Session["UserName"].ToString()==null))
                {

                    strVal = ((string)Session["UserName"]);

                    if (AuthenticateNTUsers(strVal) == true)
                    {
                        Response.Redirect("~/mypage.aspx");
                    }
                    else
                    {
                        Response.Redirect("~/login.aspx");
                       
                    }
                }
               else
                    {
                        Response.Redirect("~/login.aspx");
                       
                    }
}
0
 

Author Comment

by:Angela4eva
ID: 33731025
it stil going in infinite loop. I think it has to do with the back that response.redirect does not poastback. Any other ideas
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
himanshut earned 1000 total points
ID: 33731031
Oops.. it was otherway around :)
if (!Page.IsPostBack)
            {
               

                if ((Session["UserName"].ToString()=="") || (Session["UserName"].ToString()==null))
                {

                    Response.Redirect("~/login.aspx");
                       
                }
               else
                    {
                       strVal = ((string)Session["UserName"]);

                    if (AuthenticateNTUsers(strVal) == true)
                    {
                        Response.Redirect("~/mypage.aspx");
                    }
                    else
                    {
                        Response.Redirect("~/login.aspx");
                       
                    }
                        
                    }
}

Open in new window

0
 
LVL 10

Expert Comment

by:himanshut
ID: 33731082
in the previous code, I mistakenly put wrong code in if else conditions:

In the above code:
If Session is Empty or NULL it will redirect to login.aspx
otherwise it will continue the normal processing.

Can you put a breakpoint and debug it line by line to see if it comes into the if condition, also what is the value for the Session["UserName"].ToString().
Does it has username string value or not.

Cheers!
0
 

Author Comment

by:Angela4eva
ID: 33731138
yes its coming to if but let me tell you that this code itself is in login.aspx and so when i do response.redirect it is not causing postback its executing it everytime
0
 
LVL 20

Expert Comment

by:informaniac
ID: 33731417
Can you tell us the design of the login page? And why do you want to do the authentication on page load
0
 
LVL 10

Assisted Solution

by:codingbeaver
codingbeaver earned 1000 total points
ID: 33735990
Remove your "else" block in your code.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 33736519
--->above code is part of login.aspx page as well

If it is the login page, you don't need to Redirect to login.aspx at all. If you don't redirect, it will stay on that page.
Or is it that you are using a BasePage class  that the login inherits from or master page Load?

If that is the case then you can check if it is request from Login.aspx and if so then don't do a redirect like:

string filename = VirtualPathUtility.GetFileName(Request.Path);
                if (filename != "Login.aspx")
                {
                    Response.Redirect("~/Login.aspx");
                }

Check this: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_26466964.html
0
 

Author Closing Comment

by:Angela4eva
ID: 33771437
thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question