views:

102

answers:

2

Hi fellow stackers... I have an ASP.NET 3.5 app using forms authentication. I would like to request a page that is available to authenticated users only, but be able to display it to non authenticated users in certain scenarios. My question is at what point of the page lifecycle do I need to tell ASP.NET that is ok to display the page and how do I tell it to do so.

I've tried this to no avail:

void Application_AuthenticateRequest(Object sender, EventArgs e)
{
    HttpContext.Current.SkipAuthorization = true;
}

Of course the example above was for testing purposes only

+2  A: 

On page load why don't you use:

 if (Page.User.Identity.IsAuthenticated){
      //your code for logged in users.
 } else {

    // if not logged in.
 }

And put the page in a nonsecure directory.

waqasahmed
Because the page is set as not allowing anonymous users by ASP.NET and we would like to keep using it that way
Jonas Stawski
A: 

I'm not sure what you mean by "tried to no avail". What exactly is happening? If you are manipulating the current HTTP context to skip authorization using your method in either the BeginRequest or AuthenticateRequest (the only two request pipeline events that occur before AuthorizeRequest), it will bypass any authorization settings in your web.config file that allow or deny users.

How are you currently authorizing your requests to the page in question?

John Rasch
What I mean by "tried to no avail" is that it didn't work. It kept redirecting me to the login page. I will try using the BeginRequest event
Jonas Stawski
ok, it turns out that our base class was doing some checks and making the redirect to the Login.aspx. The problem is not ASP.NET and the code I provided above works perfectly. I tried both in the BeginRequest and AuthenticateRequest and they all work.Thanks for your help
Jonas Stawski