如何为文件管理增加一个登陆验证?

lian_yeye 2021-07-20 18:49:20
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="file_manager.aspx.cs" Inherits="WebFile.simple._1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>文件管理</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        您当前所在的位置是:<asp:Label ID="lbl_path" runat="server"></asp:Label>
        <br />
        请输入目标地址:<br />
        <asp:TextBox ID="txt_path" runat="server" Width="500px"></asp:TextBox>
        <asp:Button ID="btn_to" runat="server" OnClick="btn_to_Click" Text="转到" 
            Width="84px" />
        <br />
        转到:<br />
        <asp:DropDownList ID="ddl_path" runat="server" AppendDataBoundItems="True" 
            AutoPostBack="True" OnSelectedIndexChanged="ddl_path_SelectedIndexChanged" 
            Width="508px">
        </asp:DropDownList>
        <br />
        <asp:Button ID="btn_forward" runat="server" OnClick="btn_forward_Click" 
            Text="上一层目录" Width="115px" />
        <br />
        <br />
        <asp:GridView ID="gv_File" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="F_ID,F_name,F_exp" OnRowCommand="gv_File_RowCommand" 
            OnRowDataBound="gv_File_RowDataBound" OnRowDeleting="gv_File_RowDeleting" 
            OnSelectedIndexChanging="gv_File_SelectedIndexChanging" CellPadding="4" 
            ForeColor="#333333" GridLines="None" Height="224px" Width="693px" >
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" Height="35px" />
            <Columns>
                <asp:BoundField DataField="F_ID" HeaderText="ID" />
                <asp:TemplateField HeaderText="名称">
                    <ItemTemplate>
                        <asp:HyperLink ID="hlk_name" runat="server" Text='<%# Eval("F_name") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="类型">
                    <ItemTemplate>
                        <asp:Label ID="lb_exp" runat="server" Text='<%# Eval("F_exp") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="大小">
                    <ItemTemplate>
                    
                        <asp:HyperLink ID="lb_size" runat="server" Text='<%# Eval("F_size") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="最近修改日期">
                    <ItemTemplate>
                        <asp:Label ID="lb_time" runat="server" Text='<%# Eval("F_time") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField DeleteText="&lt;div id=&quot;de&quot; onclick=&quot;JavaScript:return confirm('确定删除吗?')&quot;&gt;删除&lt;/div&gt;" 
                    ShowDeleteButton="True" />
                <asp:ButtonField CommandName="DownLoad" Text="下载" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" 
                Height="20px" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
        <br />
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>

 file_manager.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebFile.simple
{
    public partial class _1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string F_path;
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["F_path"] == null)
                {
                    F_path = Server.MapPath(".");
                    lbl_path.Text = F_path;
                    txt_path.Text = F_path;
                    gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
                    gv_File.DataBind();
                }
                else
                {
                    F_path = Server.UrlDecode(Request.QueryString["F_path"]);
                    lbl_path.Text = F_path;
                    txt_path.Text = F_path;
                    gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
                    gv_File.DataBind();
                }

                WebDirFile.HardDiskManage.PathBindToDDl(F_path, ref ddl_path);
            }

        }

        protected void gv_File_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DownLoad")
            {
                string F_path = "";
                int index = Convert.ToInt32(e.CommandArgument);
                string name = gv_File.DataKeys[index].Values["F_name"].ToString();
                string exp = gv_File.DataKeys[index].Values["F_exp"].ToString();
                F_path = txt_path.Text;
                string FilePath = F_path + "\\" + name;


                if (WebDirFile.FileHelper.IsExist(FilePath))
                {
                    //WebDirFile.HardDiskManage.DownLoad(this, FilePath);
                    WebDirFile.HardDiskManage.download2(this, FilePath);
                }
                else
                {
                    WebDirFile.MessageBox.Show(this, "目录暂时不能下载哦");
                }


            }
        }

        protected void gv_File_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            WebDirFile.MessageBox.Show(this, gv_File.DataKeys[e.RowIndex]["F_name"].ToString());
        }

        protected void gv_File_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {

        }

        protected void gv_File_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //设置连接的地址
            if ((HyperLink)e.Row.FindControl("hlk_name") != null)
            {
                string F_path = "";
                HyperLink hlk_name = (HyperLink)e.Row.FindControl("hlk_name");
                string exp = gv_File.DataKeys[e.Row.RowIndex].Values["F_exp"].ToString();
                string name = gv_File.DataKeys[e.Row.RowIndex].Values["F_name"].ToString();
                F_path = txt_path.Text;
                string FilePath = F_path + "\\" + name;
                string url = "";

                if (WebDirFile.FileHelper.IsExist(FilePath))
                {
                    hlk_name.Target = "_blank";
                    url = WebDirFile.HardDiskManage.ConvertSpecifiedPathToRelativePath(this, FilePath);
                }
                else
                {
                    url = Request.Url.Segments[Request.Url.Segments.Length - 1].ToString() + "?F_path=" + Server.UrlEncode(F_path + "\\" + name);
                }

                hlk_name.NavigateUrl = url;

            }


        }

        protected void gv_File_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btn_to_Click(object sender, EventArgs e)
        {
            string F_path = txt_path.Text;
            gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
            gv_File.DataBind();
            txt_path.Text = F_path;
            lbl_path.Text = F_path;
        }

        protected void btn_forward_Click(object sender, EventArgs e)
        {
            string RootDir = WebDirFile.DirectoryHelper.GetParentpath(txt_path.Text);
            string F_path = RootDir;
            txt_path.Text = F_path;
            lbl_path.Text = F_path;

            if (WebDirFile.DirectoryHelper.IsExist(F_path))
            {
                gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
                gv_File.DataBind();
            }
            WebDirFile.HardDiskManage.PathBindToDDl(F_path, ref ddl_path);


        }

        protected void ddl_path_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (ddl_path.SelectedItem.Text)
            {
                case "请选择目标目录":
                    break;
                case "我的电脑":
                    break;
                case "返回上级目录":
                    string RootDir = WebDirFile.DirectoryHelper.GetParentpath(txt_path.Text);
                    string F_path = RootDir;
                    txt_path.Text = F_path;
                    lbl_path.Text = F_path;

                    if (WebDirFile.DirectoryHelper.IsExist(F_path))
                    {
                        gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
                        gv_File.DataBind();
                    }
                    WebDirFile.HardDiskManage.PathBindToDDl(F_path, ref ddl_path);
                    break;
                default:
                    F_path = ddl_path.SelectedItem.Text;
                    txt_path.Text = F_path;
                    lbl_path.Text = F_path;
                    gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
                    gv_File.DataBind();
                    break;
            }
        }
    }
}

PS:我看了书,好像不是我要的内容,头大

 

...全文
1091 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧