【发布时间】:2017-08-23 23:39:54
【问题描述】:
我创建了一个 Dynamics NAV 2016 Codeunit Web 服务(SOAP 流),我想在 ASP.NET 4 Web 应用程序中使用它。
对于身份验证,我需要使用 Windows 凭据。这是一个非常简短的代码示例。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CleanWebApp
{
using GridRef; //Web Reference
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
Grid grid = new Grid(); //New instance of the Web Service
grid.UseDefaultCredentials = true; //Use the DefaultCredentials (system credentials of the application)
//Create a table rows and cells based on the return values of the Codeunit functions
int columns = grid.SendColumnsToWeb();
int rows = grid.SendRowsToWeb();
for (int i = 0; i < rows; i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < columns; j++)
{
TableCell tc = new TableCell();
tc.Controls.Add(new LiteralControl(grid.SendDescToWeb(j + 1, i + 1)));
tr.Cells.Add(tc);
}
DynamicTable.Rows.Add(tr);
}
}
[...]
当我从 Visual Studio 运行此代码时,Web 应用程序通过 IIS Express 启动,一切正常。
现在我将这个项目发布到我的硬盘上并使用 IIS Windows 功能运行它。在浏览我的网站时,我收到 http status 401 unauthorized 错误。
在我的 IIS 管理器中启用了 Windows 身份验证。
在 system.web 块的 web.config 文件中,我添加了<authentication mode="Windows">。
当我提供硬编码凭据(用户、密码、域)并使用此代码进行身份验证 grid.Credentials = new System.Net.NetworkCredential(user, password, domain); 时,一切正常,除了凭据是以编程方式提供的......
有人对此有解决方案吗?
提前致谢
【问题讨论】:
标签: c# asp.net .net authentication iis