ASP.NET Web API - OWIN - TokenEndPointPath无法在IIS中运行

JP.*_*JP. 5 asp.net-web-api owin asp.net-web-api2

我在startup.cs中有以下代码.设置TokenEndpointPath在IIS Express中以及将Web API项目部署到IIS中的网站根目录时都能很好地工作.但是,如果我在IIS中调用令牌端点的嵌套应用程序(即网站中的应用程序),则会产生404.有没有办法将TokenEndpointPath基于实际的IIS结构而不是root,因为它在这吗?马上:

这个作品

HTTP://服务器:80/API /令牌

事实并非如此

HTTP://服务器:80 /应用/ API /令牌

    var request = HttpContext.Current.Request;
    app.UseOAuthAuthorizationServer(newOAuthAuthorizationServerOptions
    {
        AllowInsecureHttp = true,
        TokenEndpointPath = newPathString("/api/token"),
        AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(oauthTokenTimeoutInMinutes), 

        Provider = new Provider.ActiveDirectoryAuthorizationServerProvider()
    });
Run Code Online (Sandbox Code Playgroud)

BNK*_*BNK 1

正如评论所述,我已经通过设置测试了你的问题TokenEndpointPath = new PathString("/api/Token")。起初,我的connectionString样子如下:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApi-20150818041808.mdf;Initial Catalog=aspnet-WebApi-20150818041808;Integrated Security=True" providerName="System.Data.SqlClient" />    
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

将项目发布到本地 IIS (7.5) 后,将 POST 请求发送到时收到 500 错误响应

http://localhost/webapi/api/token

然后我更新connectionString如下:

<connectionStrings>    
    <add name="DefaultConnection" connectionString="Data Source=192.168.1.247;Initial Catalog=MyDB;Integrated Security=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

它的工作原理类似于下面的屏幕截图:

在此输入图像描述