Reply
Return to calling page
Old 03-06-2006, 06:23 AM Return to calling page
King Spam Talker

Posts: 1,004
Location: Manchester, UK
Hi,

I have a page on which there is a login button. The user clicks the login button and is transferred to the login page. After logging on, I want the user to be returned to the original page (as happens in this forum). How would I do this?

One method I can think of is to pass as a parameter the calling page and then response.redirect back to it, but I'd prefer to use some kind of 'RETURN' function. Does one exist? Is this the best way?
gringo is offline
Reply With Quote
View Public Profile Visit gringo's homepage!
 
When You Register, These Ads Go Away!
     
Old 03-06-2006, 11:10 AM Re: Return to calling page
sdcdesign.co.uk's Avatar
Extreme Talker

Posts: 199
Location: High Wycombe, Buckinghamshire, London
The way this website does it is if the user is not logged in, they are sent to login.php with the querystring having the page they were viewing. This is the easiest and most common way to do it.

But the way you want to, think about it, after they have logged on, they will be sent back to the login page (unless you are using PagePostBack).


To get the referring page:

Code:
Request.ServerVariables["HTTP_REFERRER"];
__________________
[ Insert witty, yet highly intelligent signature here ]
sdcdesign.co.uk is offline
Reply With Quote
View Public Profile Visit sdcdesign.co.uk's homepage!
 
Old 03-06-2006, 12:23 PM Re: Return to calling page
King Spam Talker

Posts: 1,004
Location: Manchester, UK
Right OK, so it sounds like manually retrieving the refferring page is neater than passing parameters. I'll have a play with that.

Thanks!
gringo is offline
Reply With Quote
View Public Profile Visit gringo's homepage!
 
Old 03-07-2006, 04:32 AM Re: Return to calling page
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
Look up Forms Authentication.

Basically you set your web.config up to tell ASP.NET you're using forms authentication, which pages/directories to protect, and which page to use as your login page.

When users try to access a page which is listed as protected in web.config, they are redirected automatically to the login page you specified. In the login page you then just need to perform the authentication and then call FormsAuthentication.RedirectFromLoginPage() to redirect the user to the page they origionally requested.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 03-07-2006, 06:35 AM Re: Return to calling page
King Spam Talker

Posts: 1,004
Location: Manchester, UK
Thanks Minaki. I thought about that but it didn't seem to fit what I wanted to do.

I wanted something similar to a forum where you can view the same page in 2 different modes - logged in and not logged in. The different modes allow you to do different things. So it wasn't so much a case of protecting certain pages/directories as allowing certain functionality on those pages - I don't think I can do that with forms authentication, can I?
gringo is offline
Reply With Quote
View Public Profile Visit gringo's homepage!
 
Old 03-07-2006, 08:02 AM Re: Return to calling page
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
You can still use Forms Authentication, but you will need to leave the pages unprotected and programatically restrict access to the functions. The Login button on the pages could link to the login.aspx page, passing the ReturnURL query string - this is what FormsAuthentication.RedirectFromLoginPage uses. (It also handles messy things like your cookies for you)
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 03-07-2006, 10:12 AM Re: Return to calling page
King Spam Talker

Posts: 1,004
Location: Manchester, UK
OK, I'll have a look at forms authentication when I get the chance, ta.
gringo is offline
Reply With Quote
View Public Profile Visit gringo's homepage!
 
Old 03-14-2006, 04:34 PM Re: Return to calling page
King Spam Talker

Posts: 1,004
Location: Manchester, UK
I've tried the following code but it returns the error "Value cannot be null. Parameter name: url" when I click the button.

HTML Code:
<%@ Debug="true" %>
<script runat="server">

Dim Referrer as String

    Dim greeting as String
       Sub Page_Load
       If Not IsPostback Then
         If Not Request.UrlReferrer Is Nothing Then
 	   Referrer = Request.urlreferrer.ToString()
 	 Else
 	   Referrer = "otherpage.aspx"
 	 End If
       End If
       End Sub
    
       Sub btnClick(Sender as Object, e as EventArgs)
         Response.Redirect(Referrer)
       End Sub

</script>
<html>
<head>
    <title>Testing asp.net</title>
</head>
<body>
    <form runat="Server">
        <asp:Button id="Button1" onclick="btnClick" Text="redirect" Runat="Server"></asp:Button>
    </form>
</body>
</html>
Somehow, the value of Referrer is becoming null between the page loading and the btnClick routine executing. I thought declaring that variable globally would retain its value. Does anybody know what I'm doing wrong?
gringo is offline
Reply With Quote
View Public Profile Visit gringo's homepage!
 
Reply     « Reply to Return to calling page
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14548 seconds with 13 queries