有sharepoint 2003.开发了Web部件。
当用户访问Web部件时,则在服务器端传递身份验证。
我需要在Web部件中向Web应用程序发送请求。当我向部署Web应用程序的服务器发送请求时,尝试登录已部署Web部件的服务器帐户。
当我向部署服务器的服务器发送请求时,我需要使用Web应用程序来验证访问Web部件的用户帐户。
身份验证类型:NTLM
Web部件如何转向访问Web部件的用户名的Web应用程序?
找到两种可能的解决方案:
1.在WebPart中添加Web.config,其中包含以下内容:
的
的<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<authentication mode="Windows" />
<identity impersonate="true" />
</system.web>
</configuration>
的
没有用。目前尚不清楚原因。
2.使用以下代码:
WindowsIdentity winId = (WindowsIdentity)Context.User.Identity;
WindowsImpersonationContext ctx = null;
try
{
// Start impersonating.
ctx = winId.Impersonate();
// Now impersonating.
// Access resources using the identity of the authenticated user.
_autocompleteService.SendParametersForAutoComplete(_loger,
new KeyValuePairString("performerId", performerId),
new KeyValuePairString("templatePath",
StringConverter.EncodeToURL(templatePath)),
new KeyValuePairString("specificationId", specificationId),
new KeyValuePairString("buyerId", buyerId),
new KeyValuePairString("performerCompanyId", performerCompanyId),
new KeyValuePairString("reestrItemId", reestrItemId),
new KeyValuePairString("sessionId", sessionId));
}
// Prevent exceptions from propagating.
catch
{
}
finally
{
if (ctx != null) ctx.Undo();
}
此代码来自链接:http://msdn.microsoft.com/en-us/library/aa480475.aspx
没有用。目前尚不清楚原因。
在两种情况下可能是什么原因?
答案 0 :(得分:0)
找到答案 - 为什么第二种变体不起作用。
当您模拟用户时,您可以像这样访问本地资源 用户,但不是远程资源。
如何使用第一个选项解决问题?