locked
Default.aspx RRS feed

  • Question

  • User1485910070 posted

    I was just looking at Default.aspx and it just had an empty form.  In the code behind file i noticed the Page Load sub has Response.Redirect("~/TimeTracker/TimeEntry.aspx").  I'm trying to understand why it does not state ~/TimeTracker/login.aspx") since when i try to start the app that is where I'm going.  Where in the timeentry.aspx is the login.aspx coming into play?  If anyone can shed some light on this it would be great.

    Thanks

    ------------------------------------------------------------------------------------------------------------------------------------------ Tolerance of crime breeds unending ever increasing crime.

    Wednesday, January 9, 2008 7:21 PM

Answers

  • User-507253666 posted

    You won't find it in the code behind. If you have a look in reflector at System.Web.Security.FormsAuthentication you will see:

    public static void RedirectToLoginPage(string extraQueryString)
    {
        HttpContext current = HttpContext.Current;
        string loginPage = GetLoginPage(extraQueryString);
        current.Response.Redirect(loginPage, false);
    }
     
    internal static string GetLoginPage(string extraQueryString)
    {
        return GetLoginPage(extraQueryString, false);
    }
    
     
    
     internal static string GetLoginPage(string extraQueryString, bool reuseReturnUrl) { HttpContext current = HttpContext.Current; string loginUrl = LoginUrl; if (loginUrl.IndexOf('?') >= 0) { loginUrl = RemoveQueryStringVariableFromUrl(loginUrl, "ReturnUrl"); } int index = loginUrl.IndexOf('?'); if (index < 0) { loginUrl = loginUrl + "?"; } else if (index < (loginUrl.Length - 1)) { loginUrl = loginUrl + "&"; } string str2 = null; if (reuseReturnUrl) { str2 = HttpUtility.UrlEncode(GetReturnUrl(false), current.Request.QueryStringEncoding); } if (str2 == null) { str2 = HttpUtility.UrlEncode(current.Request.PathWithQueryString, current.Request.ContentEncoding); } loginUrl = loginUrl + "ReturnUrl=" + str2; if (!string.IsNullOrEmpty(extraQueryString)) { loginUrl = loginUrl + "&" + extraQueryString; } return loginUrl; } The GetLoginPage(string extraQueryString, bool reuseReturnUrl) basically gets the requested url (in your case the TimeEntry page) and appends it to the querystring of the login page (specified in web.config) as the return url.
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 10, 2008 7:16 PM

All replies

  • User-507253666 posted

    If you're not authenticated, upon trying to access a page that requires authentication you will be automatically redirected to the login page (as specified in the web.config). You might notice when you are redirected to the login page that the url query string contains ReturnUrl with the the TimeEntry page set as the value...

    Wednesday, January 9, 2008 8:13 PM
  • User1485910070 posted

    Thank you for this info - i'm guessing its loginUrl="~/TimeTracker/login.aspx where this URL is taken?  Also where in the code-behind file of TimeEntry.aspx is the command to redirect based on the URL specified in web.config?  I can't seem to find the line of code that is causing this redirection to happen.

    Thursday, January 10, 2008 7:06 PM
  • User-319574463 posted

    Try checking the IIS logs and see what pages have been called. 

    Thursday, January 10, 2008 7:15 PM
  • User-507253666 posted

    You won't find it in the code behind. If you have a look in reflector at System.Web.Security.FormsAuthentication you will see:

    public static void RedirectToLoginPage(string extraQueryString)
    {
        HttpContext current = HttpContext.Current;
        string loginPage = GetLoginPage(extraQueryString);
        current.Response.Redirect(loginPage, false);
    }
     
    internal static string GetLoginPage(string extraQueryString)
    {
        return GetLoginPage(extraQueryString, false);
    }
    
     
    
     internal static string GetLoginPage(string extraQueryString, bool reuseReturnUrl) { HttpContext current = HttpContext.Current; string loginUrl = LoginUrl; if (loginUrl.IndexOf('?') >= 0) { loginUrl = RemoveQueryStringVariableFromUrl(loginUrl, "ReturnUrl"); } int index = loginUrl.IndexOf('?'); if (index < 0) { loginUrl = loginUrl + "?"; } else if (index < (loginUrl.Length - 1)) { loginUrl = loginUrl + "&"; } string str2 = null; if (reuseReturnUrl) { str2 = HttpUtility.UrlEncode(GetReturnUrl(false), current.Request.QueryStringEncoding); } if (str2 == null) { str2 = HttpUtility.UrlEncode(current.Request.PathWithQueryString, current.Request.ContentEncoding); } loginUrl = loginUrl + "ReturnUrl=" + str2; if (!string.IsNullOrEmpty(extraQueryString)) { loginUrl = loginUrl + "&" + extraQueryString; } return loginUrl; } The GetLoginPage(string extraQueryString, bool reuseReturnUrl) basically gets the requested url (in your case the TimeEntry page) and appends it to the querystring of the login page (specified in web.config) as the return url.
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 10, 2008 7:16 PM
  • User555306248 posted

    Check in web.config loginUrl="~/TimeTracker/login.aspx

    If you are not authenticated then it will redire to login.aspx

    Thursday, January 10, 2008 10:48 PM
  • User1485910070 posted

    Hi Mercury,

     Thanks for this info which was helpful.  Where can I find this reflector that you mentioned?

    Thanks.

    Friday, January 11, 2008 11:44 AM
  • User-319574463 posted

     You can download the reflector from http://www.aisto.com/roeder/dotnet/

    Friday, January 11, 2008 4:55 PM
  • User555306248 posted

    Thanks, It will help me & other people

    Monday, January 14, 2008 10:31 PM