【发布时间】:2013-04-27 16:46:32
【问题描述】:
我有一个 ASP.NET MVC 网站,它使用 ASP.NET WebAPI 进行身份验证。我使用 ThinkTecture IdentityModel 进行基本身份验证和会话令牌,这在本地和 Azure 网站中都可以正常工作。但是,我不得不迁移到 Azure 云服务,现在我无法使用令牌进行身份验证,总是收到 401 错误,但只有用户名和密码可以正常工作。
我能猜到的唯一区别是我现在必须处理 IIS。是否需要进行任何修改才能允许使用令牌进行身份验证?
更新:
我没有使用任何 Web.Config 配置进行身份验证,只是在 WebAPIConfig 中使用以下代码。
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var authConfig = new AuthenticationConfiguration
{
RequireSsl = true,
EnableSessionToken = true,
SendWwwAuthenticateResponseHeaders = true,
SessionToken = new SessionTokenConfiguration()
{
DefaultTokenLifetime = System.TimeSpan.FromDays(1.0)
}
};
// setup authentication against membership
authConfig.AddBasicAuthentication(
(userName, password) => WebSecurity.Login(userName, password, true)
);
config.MessageHandlers.Add(new AuthenticationHandler(authConfig));
}
【问题讨论】:
-
为了提供帮助,请在您的 web.confg 中提供以下部分:
system.web\authentication、system.web\authorization、system.webserver\modules、system.identitymodel和system.identitymodel.services -
@DaveA 我没有使用身份服务器。我有一个需要身份验证的 API,并且正在使用 Thinktecture.IdentityModel 和 WebMatrix.WebData.WebSecurity 来验证每个请求。
-
@astaykov 我没有与这些元素相关的任何设置。我需要吗?
-
您使用的是单个实例还是多个实例?
标签: iis asp.net-mvc-4 azure azure-web-roles thinktecture-ident-model