views:

92

answers:

4

I am working on a site that needs to restrict access to pages and documents(.pdf, .doc, etc) to registered users. We are using the ASP.NET Membership classes to do this. But, I'm having trouble getting it to work how I would like if someone clicks a link to a document before they are logged into the site. Currently, they will be taken to the login page and upon successful login, the document will be served in a new window, but they will still be setting at the login screen when they close the document. What can be done to send the user to a default page and also load the document?

+1  A: 

could you do something that if the ReturnURL contains a link to the actual document, you set the OnClientclick property of your "login button" to call a javascript function to open the file in a new window, and then have a Response.Redirect() to take the person from the login screen?

Jack Marchetti
This did not work for me as the JavaScript was firing before login was completed.
The Talking Walnut
A: 

Added formsAuthentication. FormsAuthentication.RedirectFromLoginPage(txtUserid.Text.Trim(), false)

Henry Gao
Correct me if I'm wrong, but that will bring up the document(.pdf, .doc, etc), but when the document window is closed, the user will still be on the login page.
The Talking Walnut
A: 

As HenryGao said, but remember to put the tag into your web config and put deny users="?" to only allow auth'd users.

<configuration>
   <system.web>
      <authorization>
         <deny users="?"/>
      </authorization>
   </system.web>
</configuration>
Antony Koch
+1  A: 

First make your own log in page; this is fairly straightforward as ASP.NET Membership provides methods to do all of the important operations. Then, right before you call the RedirectFromLoginPage method, look at the ReturnUrl query parameter value, and if it is a document, send the user to your default page instead, passing the URL for the document either as a query string parameter or in session state. Finally, in your default page, detect if a document URL was passed, and if so, do a client-side redirect (using either JavaScript or META refresh) to the document when the page is loaded.

William Gross
William, I think your solution would have worked as well, but I tried Jack's first and it worked for me.
The Talking Walnut
I ended up implementing this solution.
The Talking Walnut
That's great to hear!
William Gross