如何:用户必须登录才能下载文件 [英] How to :user must login then can download file

查看:778
本文介绍了如何:用户必须登录才能下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

我有一个内置在asp.net(C#)中的网站.
现在我有一个问题,当用户单击链接下载我们的文件(例如doc,rar文件类型)时,我的网站可以检查:他们是否登录?
如果是,则下载文件
其他
我的网站将重定向到登录页面吗?

我该怎么办?
拜托!

感谢您的阅读.
-------------------------------------------------- ---------------------
SOHOA,côngnghệnhậndạng,nhậndạngvănbản,sốhóatàiliệu,sốhóavănbản,sốhóadữliệu,s hóathôngtin,giảiphápsốhóa,phầnmềmnhậndạng

vtv tho thao,bóngđá,世界杯

Hello.

I have a webiste which built in asp.net (C#).
Now i have a problem, when user click a link to download our file (such as doc,rar file type), my website could check that : Are they logined?
IF Yes then Download file
else
my website will redirect to login page?

How can i do it?
Please!

Thank for your reading.
-----------------------------------------------------------------------
SOHOA, công nghệ nhận dạng, nhận dạng văn bản, số hóa tài liệu, số hóa văn bản, số hóa dữ liệu, số hóa thông tin, giải pháp số hóa, phần mềm nhận dạng

vtv thể thao, bóng đá, worldcup

推荐答案

解决方案1(快速方法)

在Global.asax文件中处理AuthenticateRequest 事件.

Solution 1 (Quick Way)

Handel the AuthenticateRequest event in the Global.asax file.

protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        string url = HttpContext.Current.Request.Url.AbsolutePath;
        string extension = System.IO.Path.GetExtension(url);
        switch (extension.ToLower())
        {
            case ".doc":
            case ".rar":
            case ".zip": //And so on
                if (HttpContext.Current.User == null || !HttpContext.Current.User.Identity.IsAuthenticated)
                    Response.Redirect("Login.aspx");
                  break;
        }
    }




解决方案2(更好的方式)

将所有可下载文档存储在一个文件夹中,然后在该文件夹上应用身份验证规则.




Solution 2 (Better Way)

Store all of your downloadable document in a folder and apply the authentication rules on that.

<configuration>
   <location path="Download">
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
</configuration>




解决方案3(最佳方法)

编写Http处理程序并向其传递文档标识符,处理程序负责检查用户凭据后呈现文件.




Solution 3 (Best Way)

Write a Http Handler and pass a document identifier to it, it will be the responsibility of the handler to render the file after checking the user credential.


您可以将用户登录信息存储在数据库或会话中.

在下载页面中,检查用户是否登录.如果已登录,则该链接应指向该文件,否则该链接将指向在查询字符串中具有下载文件详细信息的登录"页面.如果用户通过重定向的登录"页面登录,则可以检查查询字符串,并可以直接引导用户从那里下载页面.

希望有帮助!
You may store a user login information in the database or in a session.

In the download page, check if the user is logged in or not. If logged in the link should point to the file otherwise the link will point to the Login page with download file details in the query string. If the user logs in through the redirected Login page, the query string can be checked and the user can directly be taken to download page from there.

Hope that helps!


这篇关于如何:用户必须登录才能下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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