[英]Getting some Security issues with IIS
我的代碼背后
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo theFolder = new DirectoryInfo(@"C:\temp\Server_Attachments\6");
string Attachment = "";
foreach (FileInfo nextFile in theFolder.GetFiles())
{
Attachment += "<a href=\"C:\\temp\\Server_Attachments\\6\\blabla.xls\">" + nextFile.ToString() + "</a><br />";
div1.InnerHtml = Attachment;
}
}
protected void Attach_File(object sender, EventArgs e)
{
FileUpload1.SaveAs(@"C:\Server_Attachments\6");
}
}
我的HTML頁面是這樣的
<div id="div1" runat="server"></div>
<asp:Label ID="Label1" runat="server" Text=" Attach a file : "></asp:Label><br />
<asp:FileUpload ID="FileUpload1" runat="server" Font-Names="Tahoma" Font-Size="Small" />
<br />
<asp:Button ID="Button2" runat="server" Text=" Attach " Font-Names="Tahoma" Font- Size="Small" OnClick="Attach_File" />
既沒有超鏈接,也沒有上傳工作:(
當我點擊超鏈接時,沒有發生任何事情(雖然“目標另存為”正在運行)。
當我嘗試上傳時,我收到錯誤“訪問路徑'C:\\ Server_Attachments \\ 6'被拒絕。”
這顯然是一個安全問題。 我已經檢查了哪個帳戶正在運行該程序,它是NETWORK SERVICE。
我該如何解決 ? 我可以完全訪問NETWORK SERVICE嗎? 它安全嗎?
您應該考慮整個應用程序的權限以及它可以訪問的資源。
好的做法是在服務器上創建一個新用戶,從用戶組中刪除它並將其添加為IIS_IUSER組的成員。
現在,應用程序訪問的文件夾可以訪問該用戶,也可以為該用戶創建數據庫登錄並映射應用程序數據庫。
這樣,您的應用程序通過權限與其他應用程序隔離。
如果您想允許文件上傳,那么您就必須這樣做。 是的,這可能是一個安全問題 - 您需要確保其他所有內容都被鎖定。
為上傳文件夾提供“網絡服務”的“寫入”訪問權限。 為下載文件夾提供“網絡服務”的“讀取”訪問權限。
無需授予對網絡服務的完全控制權。
為該文件夾的IIS_IUSER提供寫訪問權限並嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.