asp.net里调用webservice, 无法得到正确的集成用户身份

pkukevin 2009-04-09 04:48:57
我现在遇到这个问题,Google了一把,发现有人跟我的问题一模一样,但是没有得到解决,我把他转过来,请大家帮帮我。

http://topic.csdn.net/u/20080203/11/565e4d04-1cc7-449a-ae9c-90e3e714359e.html

问题描述: aspx后台调用webservice, 页面和webservice都使用C#, 发布在同一台机器上, win2003server+IIS6, 都发布在IIS上, 都使用integrated windows authentication, 禁止匿名, 通过IIS访问该页面, 当前用户是 domain\user1, 页面里取当前用户是正确的domain\user1, 而Webservice里取当前用户则变成了NT AUTHORITY\NETWORK SERVICE, 这不是我想要的情况, 我希望Webservice里取当前用户仍然是domain\user1

不知是那里的问题导致? 该如何解决?

另外, 我用一个windows app引用同样的webservice, 却得到正确的当前用户domain\user1...

代码如下:

webservice: 发布在 http://localhost:8083/WebServe1/
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
string domainuser = System.Threading.Thread.CurrentPrincipal.Identity.Name;
return domainuser + "\n" + "Hello World1";
}
}
}

aspx页面: 引用http://sh-es-baoyi:8083/WebServe1/Service1.asmx, 发布在 http://localhost:8083/Client/Default.aspx
namespace Client
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
test.Service1 t = new test.Service1();

t.PreAuthenticate = true;
t.Credentials = CredentialCache.DefaultCredentials;
//t.UseDefaultCredentials = true;

Response.Write(t.HelloWorld());

}
}
}
...全文
270 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧