我们有一个控制台应用程序(C#)和Web服务器(IIS)。 Console App需要通过HTTPS POST将文件发送到Web服务器。现在,我们需要在Console App和Web Server之间添加身份验证,并且我们正在尝试使用WebClient的凭据系统。
控制台应用的上传代码:
WebClient uploadWebClient = new WebClient();
uploadWebClient.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback);
// Authentication
uploadWebClient.UseDefaultCredentials = false;
uploadWebClient.Credentials = new NetworkCredential(usernameString, passwordString);
// Upload via HTTPS POST
uploadWebClient.UploadFileAsync(new Uri(destURI), "POST", "file.ext");
服务器端代码是:
void Page_Load(object sender, EventArgs e) {
foreach(string f in Request.Files.AllKeys) {
HttpPostedFile file = Request.Files[f];
file.SaveAs("Z:\\" + file.fileName);
}
}
我们如何在服务器端实现凭据的使用?
答案 0 :(得分:1)
在IIS中使用例如Windows身份验证来保护WebSite。然后,您可以让您的用户在AD中,如果您尝试访问该页面,如果不允许用户,您将收到错误。
如果您需要检查单个用户,那么您需要将用户存储在某个地方(可能是SQL,Oracle,MySQL或任何其他数据库),然后您必须获取调用Windows用户登录信息,然后检查如果他/她能够通过查看数据库表来访问您的解决方案。
当然,如果您不需要定义角色等,您可以管理IIS中的用户。另请参阅此帖子: https://weblogs.asp.net/owscott/iis-using-windows-authentication-with-minimal-permissions-granted-to-disk (我认为这是您正在寻找的内容for!)或Windows Authentication for Specific windows user group或https://msdn.microsoft.com/en-us/library/ff647405.aspx?f=255&MSPPError=-2147217396
由于缺少详细信息,您无法给出具体答案,但这就是您可以这样做的方式。一个是Windows身份验证是IIS中的可能是web.config或IIS本身的用户管理,或者另一个解决方案是在后端获取调用用户并检查自定义数据库。