redirect not working

M

Matt Owens

I have a login page which does not redirect the user once
the code has been executed, see below. Whats strange is
it works perfectly on my localhost when debugging,
however it fails to redirect when depolyed to a remote
server. Am I missing any IIS settings or anything? The
login page just reloads once the login button has been
clicked.

Code for the login button:

private void _btnLogin_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
if (IsValidUser(txtUserName.Text,
txtPassword.Text)) //interacts with the database. This
method is fine
{
if(FormsAuthentication.GetRedirectUrl
(txtUserName.Text,false)=="/appliedbioscience/index.aspx")
{
FormsAuthentication.SetAuthCookie
(txtUserName.Text,false);
Response.Redirect
("http://www.appliedbioscience.co.uk/appliedbioscience/ind
ex.aspx",false); //fails here
}
else if
((FormsAuthentication.GetRedirectUrl
(txtUserName.Text,false).ToUpper().IndexOf("ADMIN") != -
1) && (string)Session["Role"]!="admin")
phMsg.Controls.Add(new
LiteralControl("<font color=red>ERROR: You do not have
the necessary privellages to administrate this
site</font>"));
else

FormsAuthentication.RedirectFromLoginPage
(txtUserName.Text,false); //fails here too
}
else
{
phMsg.Controls.Add(new LiteralControl
("<font color=red>ERROR: Invalid Username /
Password</font>"));
}
}

Thanks,
Matt
 
D

Daniel Fisher\(lennybacon\)

What do you want to do with this line?

if(FormsAuthentication.GetRedirectUrl
(txtUserName.Text,false)=="/appliedbioscience/index.aspx")
 
G

Guest

That line detects whether the user has come to the login
page from the homepage(index.aspx) and if so re-directs
(doesn't work) them to the index.aspx (I changed it to a
http:// address in the hope it would work as originally
it was /appliedbioscience/... type URL).

The idea behind this is that the user can login and get
access to the restricted-access documents by logging in
from the homepage. Otherwise they are taken to the login
page when they try to access some restricted content and
are redirected back to the page where they tried to
download the content from.

Hope this makes sense.

Thanks in advance for any pointers you may be able to
give.
Matt
-----Original Message-----
What do you want to do with this line?

if(FormsAuthentication.GetRedirectUrl
(txtUserName.Text,false) =="/appliedbioscience/index.aspx")



--
Daniel Fisher(lennybacon)
MCP C# ASP.NET
Blog: http://www.lennybacon.com/

I have a login page which does not redirect the user once
the code has been executed, see below. Whats strange is
it works perfectly on my localhost when debugging,
however it fails to redirect when depolyed to a remote
server. Am I missing any IIS settings or anything? The
login page just reloads once the login button has been
clicked.

Code for the login button:

private void _btnLogin_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
if (IsValidUser(txtUserName.Text,
txtPassword.Text)) //interacts with the database. This
method is fine
{
if(FormsAuthentication.GetRedirectUrl
(txtUserName.Text,false) =="/appliedbioscience/index.aspx")
{
FormsAuthentication.SetAuthCookie
(txtUserName.Text,false);
Response.Redirect
("http://www.appliedbioscience.co.uk/appliedbioscience/ind
ex.aspx",false); //fails here
}
else if
((FormsAuthentication.GetRedirectUrl
(txtUserName.Text,false).ToUpper().IndexOf("ADMIN") ! = -
1) && (string)Session["Role"]!="admin")
phMsg.Controls.Add(new
LiteralControl("<font color=red>ERROR: You do not have
the necessary privellages to administrate this
site</font>"));
else

FormsAuthentication.RedirectFromLoginPage
(txtUserName.Text,false); //fails here too
}
else
{
phMsg.Controls.Add(new LiteralControl
("<font color=red>ERROR: Invalid Username /
Password</font>"));
}
}

Thanks,
Matt


.
 
D

Daniel Fisher\(lennybacon\)

Hi Matt
That line detects whether the user has come to the login
page from the homepage(index.aspx) and if so re-directs
(doesn't work) them to the index.aspx (I changed it to a
http:// address in the hope it would work as originally
it was /appliedbioscience/... type URL).

GetRedirectUrl() Checks if the username is null, returns null in this case,
or returns Request["ReturnUrl"] if not null or just the path to the
default.aspx in the root of the application.

what does this method return in your code?
 
G

Guest

Daniel,

Locally the Redirect method returns the correct URL and
it redirects perfectly. However when I deploy to a web
server the redirect stops working. I can't debug this
remotely as I do not have the necessary permissions
however the code is the same so I can't see how this
would differ.

The fact there is a difference between remote and local
debugging makes me think its perhaps an IIS problem (only
a guess).

Any pointers would be much appreciated. Thanks for your
help

-----Original Message-----
Hi Matt
That line detects whether the user has come to the login
page from the homepage(index.aspx) and if so re-directs
(doesn't work) them to the index.aspx (I changed it to a
http:// address in the hope it would work as originally
it was /appliedbioscience/... type URL).

GetRedirectUrl() Checks if the username is null, returns null in this case,
or returns Request["ReturnUrl"] if not null or just the path to the
default.aspx in the root of the application.

what does this method return in your code?


--
Daniel Fisher(lennybacon)
MCP C# ASP.NET
Blog: http://www.lennybacon.com/






.
 
D

Daniel Fisher\(lennybacon\)

Have you tried to run the code on a different local machine or a VM?

--
Daniel Fisher(lennybacon)
MCP C# ASP.NET
Blog: http://www.lennybacon.com/



Daniel,

Locally the Redirect method returns the correct URL and
it redirects perfectly. However when I deploy to a web
server the redirect stops working. I can't debug this
remotely as I do not have the necessary permissions
however the code is the same so I can't see how this
would differ.

The fact there is a difference between remote and local
debugging makes me think its perhaps an IIS problem (only
a guess).

Any pointers would be much appreciated. Thanks for your
help

-----Original Message-----
Hi Matt
That line detects whether the user has come to the login
page from the homepage(index.aspx) and if so re-directs
(doesn't work) them to the index.aspx (I changed it to a
http:// address in the hope it would work as originally
it was /appliedbioscience/... type URL).

GetRedirectUrl() Checks if the username is null, returns null in this case,
or returns Request["ReturnUrl"] if not null or just the path to the
default.aspx in the root of the application.

what does this method return in your code?


--
Daniel Fisher(lennybacon)
MCP C# ASP.NET
Blog: http://www.lennybacon.com/






.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top