你有一個有趣的問題,空。你如何配置你的網站目錄安全?如果啓用了匿名訪問,則根據服務器的操作系統,向Everyone打開的文件夾可能不允許訪問(有關詳細信息,請參閱t his Microsoft KB Article)。
如果該網站以匿名方式運行,則可以更改該網站在IIS管理器中運行的帳戶,也可以啓用模擬。當您在Visual Studio中運行該站點時,該站點將以您的權限運行,因此Anonymous不會成爲問題。
您可以使用以下代碼輸出您的網站正在運行的用戶的身份,以幫助確定發生了什麼。您可能能夠將用戶的網站作爲網絡位置的訪問權限運行,而不需要任何假冒。標籤爲您的網頁,看看你正在運行誰爲:一個ASP添加
lblSomeLabel.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name
模擬可以打開你到更多的安全風險,所以你應該做讓之前的一些更多的閱讀這種變化 - 但是,用戶你用於模擬不需要是域管理員。在你的情況下,用戶可能只需要具有對網絡位置的完全訪問權限。
你可以閱讀更多關於如何啓用模仿on this Microsoft KB Article。下面是我建議的那個頁面的一些代碼。下面的代碼不是讓你的整個站點以模擬模式運行,而是隻運行你遇到問題的部分。
public void Page_Load(Object s, EventArgs e)
{
if(impersonateValidUser("username", "domain", "password"))
{
//Insert your code that runs under the security context of a specific user here.
undoImpersonation();
}
else
{
//Your impersonation failed. Therefore, include a fail-safe mechanism here.
}
}
private bool impersonateValidUser(String userName, String domain, String password)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if(RevertToSelf())
{
if(LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, ref token) != 0)
{
if(DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
{
CloseHandle(token);
CloseHandle(tokenDuplicate);
return true;
}
}
}
}
if(token!= IntPtr.Zero)
CloseHandle(token);
if(tokenDuplicate!=IntPtr.Zero)
CloseHandle(tokenDuplicate);
return false;
}
private void undoImpersonation()
{
impersonationContext.Undo();
}
此外,雖然serching安全的文章,我發現this StackOverflow question這是值得一讀。
還沒回答。 :(。是否有任何問題與我的問題??或需要更多的解釋?? – 2010-11-15 14:39:03