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?
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?
Added formsAuthentication. FormsAuthentication.RedirectFromLoginPage(txtUserid.Text.Trim(), false)
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>
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.