http iis website set up to access the file server

 

1, first open Internet Information Services (IIS) Manager, select the new site, if there is no Internet Information Services (IIS) Manager, you can add the control panel, in accordance with the Control Panel \ Programs \ Programs and Features, click Turn Windows features add Internet information, all the checkboxes, click OK, and wait for the installation to finish before had open Internet information services, as follows

 

2, add a site, select the site, add the right site, add sites pop up a form, fill in information such as website: http test site deployment file server

 

3. Switch to Features View, double-click the directory browsing area on the right, click Enable.

 

 

 

 4, similarly to the switching function of view, double WebDAV creation rules, rule creation right region select Add

 

 

Select all users, under the permission to read, source, write all the checkboxes, and click OK.

 

 Select the right area WebDAV Settings, set Request Filtering behavior and behavioral attributes, click on the right application

 

Select Enable in website testing website http deploy file servers, click the functional view, click on the right area WebDAV

 

 5, the same power switch to the view, double-click authentication, enable anonymous authentication and Windows Authentication

 

 

 

6, select the site test site http deploy file servers, right-management web browser, the browser displays the web.config file, as shown below, even if successful.

7, add users, and set up a website physical path D: \ access TestHttpDeployFileServer files under the folder TestHttpDeployFileServer

Add User: Select My Computer or Computer, right-management on the desktop, select the local user groups the user, to the right location, right blank new user,

 myjj user double-clicks to add, set the user belongs to Power Users

 

Set up a website physical path D: \ TestHttpDeployFileServer access to files under the folder 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:\download\123.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:\download\456.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:\download\123.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:\download\456.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
}
}

Guess you like

Origin www.cnblogs.com/1175429393wljblog/p/11210973.html