function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhilash Mishra 13Abhilash Mishra 13 

redirecting on the same page after login

I am using standard sitelogincontroller class 
**
 * An apex page controller that exposes the site login functionality
 */
global with sharing class SiteLoginController {
    global String username {get; set;}
    global String password {get; set;}

    global PageReference login() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return Site.login(username, password, startUrl);
    }
    
     global SiteLoginController () {}
}
Every time i login it redirect me to site home page. but i want to redirect on the very same page not on site home page.
I have tried using  startulr=apexpages.currentpage(),geturl() but  this didn't work.

Need help 
Urgent
Thanks
 
Best Answer chosen by Abhilash Mishra 13
Abhilash Mishra 13Abhilash Mishra 13
finally I have solved it. Its a work around i have to derive the relative url i.e. '/apex/pagename' from refURL paramerter in the current page and pass it as a start url.

All Answers

Waqar Hussain SFWaqar Hussain SF
global with sharing class SiteLoginController {
    global String username {get; set;}
    global String password {get; set;}

    global PageReference login() {
     //please ensure that user name and password are correct and not null 
     system.debug('username:: '+username);
      system.debug('password:: '+password);
        
        //String startUrl = System.currentPageReference().getParameters().get('startURL');
        return Site.login(username, password, '/apex/visualforce_pageName');
    }
    
     global SiteLoginController () {}
}
Abhilash Mishra 13Abhilash Mishra 13
Hi vickey,
Thanks For the reply. but its not what i am looking for. Login link is on every page of the site. so can not really fix the value of start url. i want to redirect on the same page from wich login is done.
Abhilash Mishra 13Abhilash Mishra 13
finally I have solved it. Its a work around i have to derive the relative url i.e. '/apex/pagename' from refURL paramerter in the current page and pass it as a start url.
This was selected as the best answer
Victor LockwoodVictor Lockwood
Old post but Waqar, I would strongly recommend NOT calling a system.debug() on a password parameter in production code...