要求用户登录才能使用ASP.NET查看文档 [英] Require the user to log in to view a document using ASP.NET

查看:80
本文介绍了要求用户登录才能使用ASP.NET查看文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个需要限制注册用户访问页面和文档(.pdf,.doc等)的网站上工作.我们正在使用ASP.NET成员资格类来做到这一点.

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 sitting 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?

推荐答案

首先创建您自己的登录页面;这非常简单,因为ASP.NET成员资格提供了执行所有重要操作的方法.然后,就在调用RedirectFromLoginPage方法之前,查看ReturnUrl查询参数值,如果它是一个文档,则将用户发送到您的默认页面,将文档的URL作为查询字符串参数或以会话状态传递给.最后,在您的默认页面中,检测是否传递了文档URL,如果是,则在页面加载时对客户端进行客户端重定向(使用JavaScript或META刷新).

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.

这篇关于要求用户登录才能使用ASP.NET查看文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆