Help!! RedirectFromLoginPage and GetRedirectUrl

G

Guest

Any help anyone can give me will be appreciated!!!! This is driving me
c-r-a-z-y!

All I can get from both of the above redirections is a redirect to a page
named default.aspx. How do I make either of these work? I have an app that
has two pages that need a login. I need to be able to have it automatically
return to whichever page the user came from.

I've tried both of the following (not together, of course):
[Button Submit has code to check database]
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)

[Button Submit has code to check database]
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Text, False))

My Web Config has this in it:

<authentication mode="Forms" >
<forms name=".LoginCookie" loginUrl="Login.aspx"
protection="All" timeout="40" path="/" />
</authentication>
(Although I would rather not rely on cookies since people can turn them off,
but I got this from an example in a book and couldn't find an example of how
to do it without cookies.)

I made sure in IIS the app was an app.

I originally had one of the pages in a separate folder. I thought maybe
that had something to do with it, so I cut and pasted it to the first level.
That did nothing.

Again, any suggestions will be greatly appreciated!
 
T

TJS

try this


If User.Identity.IsAuthenticated Then
[do whatever here]
Else
response.redirect("~/login.aspx")
End If
 
G

Guest

Thanks so much for your response.

The problem is not getting to the login page. It is the redirecting back to
the original page they came from.

The RedirectFromLoginPage and GetRedirectUrl are supposed to, as a fellow
programmer put it, "automagically" redirect back to the page that took them
to the login page. As I understand it, from all the reading I've done, both
in books and on the Internet, he is entirely correct . . . however, for some
reason my machine seems to have a mind of its own and is not responding
correctly. (Of course, I blame it on my box, but we both know who's the
smarter of the two . . .guess I'm doing something dumb - I haven't found an
instance where anyone has had a problem with this.)

Can you give me another clue?

Again, thanks so much for your response! This is sooooo frustrating!
--
Sandy


TJS said:
try this


If User.Identity.IsAuthenticated Then
[do whatever here]
Else
response.redirect("~/login.aspx")
End If




Sandy said:
Any help anyone can give me will be appreciated!!!! This is driving me
c-r-a-z-y!

All I can get from both of the above redirections is a redirect to a page
named default.aspx. How do I make either of these work? I have an app
that
has two pages that need a login. I need to be able to have it
automatically
return to whichever page the user came from.

I've tried both of the following (not together, of course):
[Button Submit has code to check database]
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)

[Button Submit has code to check database]
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Text,
False))

My Web Config has this in it:

<authentication mode="Forms" >
<forms name=".LoginCookie" loginUrl="Login.aspx"
protection="All" timeout="40" path="/" />
</authentication>
(Although I would rather not rely on cookies since people can turn them
off,
but I got this from an example in a book and couldn't find an example of
how
to do it without cookies.)

I made sure in IIS the app was an app.

I originally had one of the pages in a separate folder. I thought maybe
that had something to do with it, so I cut and pasted it to the first
level.
That did nothing.

Again, any suggestions will be greatly appreciated!
 
T

TJS

For what it'e worth, the redirect back to the selected page before login,
doesn't work for me either.




Sandy said:
Thanks so much for your response.

The problem is not getting to the login page. It is the redirecting back
to
the original page they came from.

The RedirectFromLoginPage and GetRedirectUrl are supposed to, as a fellow
programmer put it, "automagically" redirect back to the page that took
them
to the login page. As I understand it, from all the reading I've done,
both
in books and on the Internet, he is entirely correct . . . however, for
some
reason my machine seems to have a mind of its own and is not responding
correctly. (Of course, I blame it on my box, but we both know who's the
smarter of the two . . .guess I'm doing something dumb - I haven't found
an
instance where anyone has had a problem with this.)

Can you give me another clue?

Again, thanks so much for your response! This is sooooo frustrating!
--
Sandy


TJS said:
try this


If User.Identity.IsAuthenticated Then
[do whatever here]
Else
response.redirect("~/login.aspx")
End If




Sandy said:
Any help anyone can give me will be appreciated!!!! This is driving me
c-r-a-z-y!

All I can get from both of the above redirections is a redirect to a
page
named default.aspx. How do I make either of these work? I have an app
that
has two pages that need a login. I need to be able to have it
automatically
return to whichever page the user came from.

I've tried both of the following (not together, of course):
[Button Submit has code to check database]
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)

[Button Submit has code to check database]
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Text,
False))

My Web Config has this in it:

<authentication mode="Forms" >
<forms name=".LoginCookie" loginUrl="Login.aspx"
protection="All" timeout="40" path="/" />
</authentication>
(Although I would rather not rely on cookies since people can turn them
off,
but I got this from an example in a book and couldn't find an example
of
how
to do it without cookies.)

I made sure in IIS the app was an app.

I originally had one of the pages in a separate folder. I thought
maybe
that had something to do with it, so I cut and pasted it to the first
level.
That did nothing.

Again, any suggestions will be greatly appreciated!
 
G

Guest

TJS -

Thanks again for your response! At least I know I'm not the only one . . .
Now, how do we go about getting a double-help out there on this one?????
--
Sandy


TJS said:
For what it'e worth, the redirect back to the selected page before login,
doesn't work for me either.




Sandy said:
Thanks so much for your response.

The problem is not getting to the login page. It is the redirecting back
to
the original page they came from.

The RedirectFromLoginPage and GetRedirectUrl are supposed to, as a fellow
programmer put it, "automagically" redirect back to the page that took
them
to the login page. As I understand it, from all the reading I've done,
both
in books and on the Internet, he is entirely correct . . . however, for
some
reason my machine seems to have a mind of its own and is not responding
correctly. (Of course, I blame it on my box, but we both know who's the
smarter of the two . . .guess I'm doing something dumb - I haven't found
an
instance where anyone has had a problem with this.)

Can you give me another clue?

Again, thanks so much for your response! This is sooooo frustrating!
--
Sandy


TJS said:
try this


If User.Identity.IsAuthenticated Then
[do whatever here]
Else
response.redirect("~/login.aspx")
End If




Any help anyone can give me will be appreciated!!!! This is driving me
c-r-a-z-y!

All I can get from both of the above redirections is a redirect to a
page
named default.aspx. How do I make either of these work? I have an app
that
has two pages that need a login. I need to be able to have it
automatically
return to whichever page the user came from.

I've tried both of the following (not together, of course):
[Button Submit has code to check database]
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)

[Button Submit has code to check database]
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Text,
False))

My Web Config has this in it:

<authentication mode="Forms" >
<forms name=".LoginCookie" loginUrl="Login.aspx"
protection="All" timeout="40" path="/" />
</authentication>
(Although I would rather not rely on cookies since people can turn them
off,
but I got this from an example in a book and couldn't find an example
of
how
to do it without cookies.)

I made sure in IIS the app was an app.

I originally had one of the pages in a separate folder. I thought
maybe
that had something to do with it, so I cut and pasted it to the first
level.
That did nothing.

Again, any suggestions will be greatly appreciated!
 
L

Lau Lei Cheong

Sandy,

If everything else fails, you can append the current page's encoded URL to
your login page's URL(i.e.: Response.Redirect("login.aspx?currpage=" +
HttpUtility.UrlEncode(Request.RawUrl))).

When authenication success, redirect the user using
Response.Redirect(HttpUtility.UrlDecode(Request.QueryString["currpage"]));

Regards,
Lau Lei Cheong
 
L

Lee

When ASP.Net redirects you to the login page, it should append something
to the request URL so that the full url looks something like:
http://www.domain.com/login.aspx?ReturnUrl=/PreviousPage.aspx%
3f__redir%3d1&__redir=1

the appended query variables :

ReturnUrl=%2fPreviousPage.aspx%3f__redir%3d1

are an url-encoded form of :

ReturnURL=/PreviousPage.aspx?__redir=1

which is what the RedirectFromLoginPage and GetRedirectUrl methods will
use to decide where to redirect to.

Maybe these aren't present on the redirect-to-login-page URL? this would
explain why you're unable to return to the original page.
 
G

Guest

Lee -

Thank you for your response. Would you happen to have an example of what I
would put in my Login.aspx page code and what I would put in my
AddNewListing.aspx code?
 
G

Guest

Lau -

Thanks for the suggestions! I did try the
Response.Redirect("login.aspx?currpage=" +
HttpUtility.UrlEncode(Request.RawUrl))) with success. My redirect included
the correct info in the browser url address.

When I tried to use the other one, in my Login page to redirect back to the
AddNewListing page, I got the blue squiggly line under it. What dumb thing
am I neglecting to do?

--
Sandy


Lau Lei Cheong said:
Sandy,

If everything else fails, you can append the current page's encoded URL to
your login page's URL(i.e.: Response.Redirect("login.aspx?currpage=" +
HttpUtility.UrlEncode(Request.RawUrl))).

When authenication success, redirect the user using
Response.Redirect(HttpUtility.UrlDecode(Request.QueryString["currpage"]));

Regards,
Lau Lei Cheong

Sandy said:
Any help anyone can give me will be appreciated!!!! This is driving me
c-r-a-z-y!

All I can get from both of the above redirections is a redirect to a page
named default.aspx. How do I make either of these work? I have an app
that
has two pages that need a login. I need to be able to have it
automatically
return to whichever page the user came from.

I've tried both of the following (not together, of course):
[Button Submit has code to check database]
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)

[Button Submit has code to check database]
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Text,
False))

My Web Config has this in it:

<authentication mode="Forms" >
<forms name=".LoginCookie" loginUrl="Login.aspx"
protection="All" timeout="40" path="/" />
</authentication>
(Although I would rather not rely on cookies since people can turn them
off,
but I got this from an example in a book and couldn't find an example of
how
to do it without cookies.)

I made sure in IIS the app was an app.

I originally had one of the pages in a separate folder. I thought maybe
that had something to do with it, so I cut and pasted it to the first
level.
That did nothing.

Again, any suggestions will be greatly appreciated!
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top