Solution to Forms Authentication redirecting to bogus default.aspx page with RedirectFromLoginPage

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Solution to Forms Authentication redirecting to bogus default.aspx page with RedirectFromLoginPage

    hi,
    i've read a lot of posts here about people who ran into problems using
    forms authentication, and the RedirectFromLoginPage() method, which
    always redirects to a default.aspx. this is a big problem if you use
    sub-folders that don't have a default.aspx page, as in my case.
    i read some posts that suggested manually Response.Redirecting the user
    to the url in the querystring, but actually this is incorrect because
    Forms Auth puts the default.aspx in that querystring even if the user
    wasn't at a page called default.aspx.

    i put together a simple solution to get the redirecting to work
    properly, and would like to post it here for future reference:

    1. the Login page (Login.aspx) must be set up to read the
    HTTP_Referrer, and add it to the ViewState in the first Page_Load on
    that page.

    2. in the btnLogin_Click event on Login.aspx, the SetAuthCookie() event
    should be called, and the user should be Response.Redirected to the
    referrer value in the viewstate.

    Here is sample code:

    *****************
    Login.aspx
    *****************

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    ViewState["originalUrl"] = Request.UrlReferrer.AbsoluteUri;
    }

    private void btnLogin_Click(object sender, System.EventArgs e)
    {
    string originalUrl = ViewState["originalUrl"];
    if(originalUrl == null || originalUrl == "") // in case the viewstate
    is corrupt, use default.aspx by 'default'
    originalUrl = "default.aspx";

    // do your password checking here
    // if it's all ok then...
    FormsAuthentication.SetAuthCookie(username, false);
    Response.Redirect(originalUrl, true);
    }

    Tim_Mac Guest

  2. Similar Questions and Discussions

    1. Forms Authentication - Not timing out, not redirecting.
      Hi, I've come across this scenario in ASP.NET 1.1 with forms authentication where the forms auth doesn't seem to timeout correctly, nor redirect to...
    2. Redirecting anon users - Forms or Windows Authentication
      I have an Intranet site that I'm trying to work out some authentication issues on. Eventually, I want all of our domain users to add the url for the...
    3. RedirectFromLoginPage not redirecting
      I'm attempting to use Forms/Roles based authentication and authorization. A subdirectory's web.config allows only "Admin" roles and it does kick...
    4. Security alert when redirecting the user from aspx to asp page
      Hi, I get a security alert when I redirect a user from aspx page to asp page. Both the pages are present on the same web site and Https is...
    5. redirecting from .aspx page to .asp page
      There is no great way to share session state between ASP and ASP.NET. But that doesn't mean you don't have options. Here are some common ways:...
  3. #2

    Default Re: Solution to Forms Authentication redirecting to bogus default.aspx page with Redi

    what u suggest is correct but if anyone want to use the same code, see the following soln.


    FormsAuthentication.RedirectFromLoginPage will redirect to the default page specified in your <forms defaultUrl> tag in your web.config file; so u just modify <forms defaultUrl="someother.aspx"> in web.config and it automatically redirect into someother.aspx page.

    Regards,
    Subrata K
    Subrata K Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139