• iis网站搭建http访问的文件服务器


    1、首先打开Internet信息服务(IIS)管理器,选择新建网站,如果没有Internet信息服务(IIS)管理器,可以在控制面板添加,按照 控制面板程序程序和功能,点击 打开或关闭Windows功能,添加 Internet信息,全部勾选,点击 确定,等待安装完成,之后再打开就有Internet信息服务,操作如下

    2、添加网站,选择 网站,右键 添加网站,弹出添加网站窗体,填写网站信息 如:测试http网站部署文件服务器

    3、切换到 功能视图,双击 目录浏览 ,右侧区域,点击  启用。

     

     4、同样 切换到 功能视图,双击 WebDAV创作规则,右侧区域 选择 添加创作规则

    选择 所有用户,权限下的读取,源,写入全部勾选,点击确定。

     选择 右侧区域  WebDAV设置,设置请求筛选行为和属性行为,点击 右侧 应用

    在选择网站测试http网站部署文件服务器,点击功能视图,右侧区域 点击 启用WebDAV

     5、同样 切换到功视图,双击  身份验证,启用 匿名身份验证和Windows身份验证

     

    6、选择网站 测试http网站部署文件服务器,右键 管理网站  浏览 ,浏览器显示web.config文件,如下图,即使成功。

    7、添加用户和设置网站物理路径D:TestHttpDeployFileServer下的文件夹的访问权限TestHttpDeployFileServer

    添加用户:选择桌面上的  我的电脑或计算机,右键 管理,选择 本地用户组下用户,右侧空白位置 右键 新用户,

     双击 添加的myjj用户,设置 用户 隶属于  Power Users

    设置网站物理路径D:TestHttpDeployFileServer下的文件夹的访问权限TestHttpDeployFileServer:

    选择文件夹TestHttpDeployFileServer,右键属性,选择 安全 设置myjj用户所属用户组的权限即可,如果没有 Power Users用户组,就选择 添加 高级 立即查找,然后选择 Power Users点击确定,即可设置访问权限

     

    8、经过上述步骤,一个网站的http访问的文件服务器已经架设成功了,下面就可以使用了,具体如下

     新建控制台项目程序,Program.cs内容如下:

    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Text;

    namespace ConsoleApp1
    {
    class Program
    {
    static void Main(string[] args)
    {
    TestWebclient testWebclient = new TestWebclient();
    testWebclient.WebClientUpload();//上传
    testWebclient.WebClientDownload();//下载
    testWebclient.WebClientdelete();//删除
    //WebClientDownload();//下载
    //WebClientUpload();//上传
    //WebClientDelete();//删除
    Console.ReadKey();
    }

    #region 下载
    /// <summary>
    /// 下载
    /// </summary>
    static void WebClientDownload()
    {
    WebClient webClient = new WebClient
    {
    Credentials = CredentialCache.DefaultCredentials
    };
    //Uri _uri = new Uri(@"http://localhost:8082/123.txt");
    Uri uri = new Uri(@"http://192.168.0.100:8082/123.txt");
    webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
    webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
    webClient.DownloadFileAsync(uri, @"D:download123.txt");
    }

    private static void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
    {
    Console.WriteLine("下载完成...");
    }

    private static void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
    Console.WriteLine($"{e.ProgressPercentage}:{e.BytesReceived}/{e.TotalBytesToReceive}");
    }

    #endregion

    #region 上传

    /// <summary>
    /// 上传
    /// </summary>
    static void WebClientUpload()
    {
    WebClient webClient = new WebClient
    {
    Credentials = new NetworkCredential("test", "123")
    };
    Uri uri = new Uri(@"http://192.168.0.100:8082/456.xlsx");
    webClient.UploadProgressChanged += WebClient_UploadProgressChanged;
    webClient.UploadFileCompleted += WebClient_UploadFileCompleted;
    webClient.UploadFileAsync(uri, "PUT", @"D:download456.xlsx");
    }

    private static void WebClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
    {
    Console.WriteLine("上传完成...");
    }

    private static void WebClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
    {
    Console.WriteLine($"{e.ProgressPercentage}:{e.BytesSent}/{e.TotalBytesToSend}");
    }
    #endregion

    #region 删除
    /// <summary>
    /// 删除
    /// </summary>
    static void WebClientDelete()
    {
    WebClient webClient = new WebClient
    {
    Credentials = new NetworkCredential("test", "123")
    };
    Uri uri = new Uri(@"http://192.168.0.100:8082/456.xlsx");
    webClient.UploadDataCompleted += WebClient_UploadDataCompleted;
    webClient.UploadDataAsync(uri, "DELETE", new byte[0]);
    }

    private static void WebClient_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
    {
    Console.WriteLine("已删除...");
    }
    #endregion
    }

    }

    TestWebclient类代码如下:

    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Text;

    namespace ConsoleApp1
    {
    public class TestWebclient
    {
    #region 下载
    public void WebClientDownload()
    {
    WebClient webClient = new WebClient();
    webClient.Credentials = CredentialCache.DefaultCredentials;
    Uri uri = new Uri(@"http://localhost:8087/123.txt");

    webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
    webClient.DownloadDataCompleted += WebClient_DownloadDataCompleted;
    webClient.DownloadFileAsync(uri, @"D:download123.txt");
    }

    private static void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
    Console.WriteLine($"已下载百分比:{e.ProgressPercentage}:{e.BytesReceived / e.TotalBytesToReceive}");
    }

    private static void WebClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
    {
    Console.WriteLine("下载完成...");
    }

    #endregion

    #region 上传
    public void WebClientUpload()
    {
    WebClient webClient = new WebClient();
    //webClient.Credentials = new NetworkCredential("test123","123");
    webClient.Credentials = CredentialCache.DefaultCredentials;
    Uri uri = new Uri(@"http://localhost:8087/456.xlsx");

    webClient.UploadProgressChanged += WebClient_UploadProgressChanged;
    webClient.UploadFileCompleted += WebClient_UploadFileCompleted;
    webClient.UploadFileAsync(uri, "put", @"D:download456.xlsx");
    }

    private void WebClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
    {
    Console.WriteLine("上传完成");
    }

    private void WebClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
    {
    Console.WriteLine($"{e.ProgressPercentage}:{e.BytesSent/e.TotalBytesToSend}");
    }
    #endregion

    #region 删除
    public void WebClientdelete()
    {
    WebClient webClient = new WebClient();
    webClient.Credentials = new NetworkCredential("test123","123");
    //webClient.Credentials = CredentialCache.DefaultCredentials;
    Uri uri = new Uri(@"http://localhost:8087/456.xlsx");

    webClient.UploadDataCompleted += WebClient_UploadDataCompleted;
    webClient.UploadDataAsync(uri, "DELETE", new byte[0]);
    }

    private void WebClient_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
    {
    Console.WriteLine("已删除");
    }
    #endregion
    }
    }

  • 相关阅读:
    ngx-bootstrap使用04 carousel组件
    ngx-bootstrap使用03 Alerts组件、利用Object.assign复制对象
    ngx-bootstrap使用02 Accordion组件的使用
    ngx-bootstrap使用01 安装ngx-bootstrap和bootstrap及其使用、外部样式引入
    SpringBoot11 读取properties文件、发送邮件
    SpringBoot10 整合JSP
    SpringBoot09 自定义servlet、注册自定义的servlet、过滤器、监听器、拦截器、切面、webmvcconfigureradapter过时问题
    红帽系统制作yum本地源
    利用python数据分析panda学习笔记之基本功能
    利用python数据分析panda学习笔记之DataFrame
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/11210973.html
Copyright © 2020-2023  润新知