Ask a Question related to ASP.NET Security, Design and Development.
-
Matt Owens #1
redirect not working
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
Matt Owens Guest
-
ADDT Redirect not working properly
I have a dynamic list with 3 dynamic forms which sort of act like a wizard where you select the record you want to edit from the dynamic list and... -
Response.ReDirect / FormsAuth.ForwardFromLogin not working
Instead of doing :- FormsAuthentication.SetAuthCookie (txtUserName.Text,false); Response.Redirect... -
response.redirect to an HTTPS not working
I have a web from that based on the user's response needs to go to a web folder set up with SSL. My problem is that when the redirect is executed I... -
Response.redirect only working sometimes
I have response.redirect("/home.asp") in my code but instead of redirecting to that page it sometimes redirects to the current page... -
redirect to .net 1.0 assemblies not working
Snippet from web.config: <startup> <supportedRuntime version="v1.0.3705" /> <requiredRuntime version="v1.0.3705" safemode="true"/> </startup>... -
Daniel Fisher\(lennybacon\) #2
Re: redirect not working
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: [url]http://www.lennybacon.com/[/url]
"Matt Owens" <anonymous@discussions.microsoft.com> wrote in message
news:422201c4abae$0f994a60$a301280a@phx.gbl...>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
>
>
Daniel Fisher\(lennybacon\) Guest
-
Re: redirect not working
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=="/appliedbioscience/index.aspx")>-----Original Message-----
>What do you want to do with this line?
>
>if(FormsAuthentication.GetRedirectUrl
>(txtUserName.Text,false)in message>
>
>
>--
>Daniel Fisher(lennybacon)
> MCP C# ASP.NET
>Blog: [url]http://www.lennybacon.com/[/url]
>
>"Matt Owens" <anonymous@discussions.microsoft.com> wroteonce>news:422201c4abae$0f994a60$a301280a@phx.gbl...>>I have a login page which does not redirect the user=="/appliedbioscience/index.aspx")>> 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)("http://www.appliedbioscience.co.uk/appliedbioscience/ind>> {
>> FormsAuthentication.SetAuthCookie
>> (txtUserName.Text,false);
>> Response.Redirect
>>= ->> 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
>>
>>
>
>.
>Guest
-
Daniel Fisher\(lennybacon\) #4
Re: redirect not working
Hi Matt
GetRedirectUrl() Checks if the username is null, returns null in this case,> 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).
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: [url]http://www.lennybacon.com/[/url]
Daniel Fisher\(lennybacon\) Guest
-
Re: redirect not working
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
login>-----Original Message-----
>Hi Matt
>>> That line detects whether the user has come to thea>> page from the homepage(index.aspx) and if so re-directs
>> (doesn't work) them to the index.aspx (I changed it tonull in this case,>>> http:// address in the hope it would work as originally
>> it was /appliedbioscience/... type URL).
>GetRedirectUrl() Checks if the username is null, returnspath to the>or returns Request["ReturnUrl"] if not null or just 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: [url]http://www.lennybacon.com/[/url]
>
>
>
>
>
>
>.
>Guest
-
Daniel Fisher\(lennybacon\) #6
Re: redirect not working
Have you tried to run the code on a different local machine or a VM?
--
Daniel Fisher(lennybacon)
MCP C# ASP.NET
Blog: [url]http://www.lennybacon.com/[/url]
<anonymous@discussions.microsoft.com> wrote in message
news:155e01c4ac50$45979660$a401280a@phx.gbl...> 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
>
>> login>>-----Original Message-----
>>Hi Matt
>>>>> That line detects whether the user has come to the> a>>> page from the homepage(index.aspx) and if so re-directs
>>> (doesn't work) them to the index.aspx (I changed it to> null in this case,>>>>> http:// address in the hope it would work as originally
>>> it was /appliedbioscience/... type URL).
>>GetRedirectUrl() Checks if the username is null, returns> path to the>>or returns Request["ReturnUrl"] if not null or just 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: [url]http://www.lennybacon.com/[/url]
>>
>>
>>
>>
>>
>>
>>.
>>
Daniel Fisher\(lennybacon\) Guest
-
Ldraw #7
Redirect not working
I have looked at all the Redirect questions on this site without finding a
resoultion
to my redirect problem. I am using sample code to verify a user and
password from a login page but although the verification is successful and I
can see that the return url is where I need to go I am continously looped
back to the login page.
Cookies are enabled. See code example below.
--WebConfig--
<authentication mode="Forms">
<forms name="TestLoginAthu" path="/" loginUrl="WebForm1.aspx"
protection="All" timeout="30">
<credentials passwordFormat="Clear">
<user name="jeff" password="test" />
<user name="mike" password="test" />
</credentials>
</forms>
</authentication>
--Code Behind
HttpCookie cookie = FormsAuthentication.GetAuthCookie ( TextBox1.Text,
CheckBox1.Checked );
// Expires in 30 days, 12 hours and 30 minutes from today.
cookie.Expires = DateTime.Now.Add(new TimeSpan(30, 12, 30, 0));
Response.Cookies.Add (cookie);
string strUrl = FormsAuthentication.GetRedirectUrl ( TextBox1.Text,
CheckBox1.Checked );
Response.Redirect( strUrl );
Ldraw Guest
-
Mark Miller #8
Re: Redirect not working
As far as I can tell you have protection set to "All" which uses encryption
for the cookie. But you are not ecrypting the cookie before you write it to
the Response stream. I'm not sure how to encrypt a cookie after calling
GetAuthCookie() but an alternative is to create a FormsAuthentication ticket
and then use the FormsAuthentication.Encrypt() method passing in the ticket.
Your sample it should give you the exact same functionality you need. Here's
a sample:
//create ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(30), true,
string.Empty);
//encrypt ticket and capture string result
string sEncryptedTicket = FormsAuthentication.Encrypt( ticket );
//create a new cookie and add it to the Response stream
Response.Cookies.Add( new System.Web.HttpCookie(
FormsAuthentication.FormsCookieName, sEncryptedTicket ) );
I hope that helps.
Regards,
Mark
"Ldraw" <Ldraw@discussions.microsoft.com> wrote in message
news:5A215232-5333-4AA1-BA5E-F4AC3BD5FFAE@microsoft.com...>I have looked at all the Redirect questions on this site without finding a
> resoultion
> to my redirect problem. I am using sample code to verify a user and
> password from a login page but although the verification is successful and
> I
> can see that the return url is where I need to go I am continously looped
> back to the login page.
> Cookies are enabled. See code example below.
>
> --WebConfig--
> <authentication mode="Forms">
> <forms name="TestLoginAthu" path="/" loginUrl="WebForm1.aspx"
> protection="All" timeout="30">
> <credentials passwordFormat="Clear">
> <user name="jeff" password="test" />
> <user name="mike" password="test" />
> </credentials>
> </forms>
> </authentication>
>
> --Code Behind
>
> HttpCookie cookie = FormsAuthentication.GetAuthCookie ( TextBox1.Text,
> CheckBox1.Checked );
> // Expires in 30 days, 12 hours and 30 minutes from today.
> cookie.Expires = DateTime.Now.Add(new TimeSpan(30, 12, 30, 0));
> Response.Cookies.Add (cookie);
> string strUrl = FormsAuthentication.GetRedirectUrl ( TextBox1.Text,
> CheckBox1.Checked );
> Response.Redirect( strUrl );
Mark Miller Guest
-
rob kelly via DotNetMonster.com #9
Re: Redirect not working
Check to see if you have smart navigation turned on for the login page. I had the same problem, turning this off seemed to have solved it.
--
Message posted via [url]http://www.dotnetmonster.com[/url]
rob kelly via DotNetMonster.com Guest



Reply With Quote

