我的startup.cs 中有以下代码。当 Web API 项目部署到 IIS 中网站的根目录时,在 IIS Express 中设置 TokenEndpointPath 效果非常好。但是,如果我托管在 IIS 中的嵌套应用程序(即网站内的应用程序)中,对令牌端点的调用会导致 404。有没有办法使 TokenEndpointPath 基于实际 IIS 结构而不是根,因为它这里有吗?现在:
这有效
http://服务器:80/api/token http://server:80/api/token
这不
http://服务器:80/app/api/token http://server:80/app/api/token
var request = HttpContext.Current.Request;
app.UseOAuthAuthorizationServer(newOAuthAuthorizationServerOptions
{
AllowInsecureHttp = true,
TokenEndpointPath = newPathString("/api/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(oauthTokenTimeoutInMinutes),
Provider = new Provider.ActiveDirectoryAuthorizationServerProvider()
});
正如评论的那样,我通过设置测试了你的问题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>
将项目发布到本地 IIS (7.5) 后,将 POST 请求发送到时收到 500 错误响应
http://localhost/webapi/api/token 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>
它的工作原理类似于下面的屏幕截图:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)