我正在使用ssl的基本身份验证,当我调试我的web api时,一切似乎都运行正常。 IsAuthorized方法被调用,它到目前为止工作。但是当我将webapi发布到服务器时,我收到以下错误消息
错误有 发生了。没有连接到Sql数据库。 System.Web.HttpException System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(字符串 fullFileName,String dataDir,String connectionString)
我甚至不知道为什么要尝试创建mdf文件,因为webapi正在使用sql server express实例。如果我删除了authorize属性,一切都运行良好。
protected override bool IsAuthorized(HttpActionContext actionContext)
{
if (Thread.CurrentPrincipal.Identity.Name == null || Thread.CurrentPrincipal.Identity.Name.Length == 0)
{ // If an identity has not already been established by other means:
AuthenticationHeaderValue auth = actionContext.Request.Headers.Authorization;
if (auth != null && string.Compare(auth.Scheme, "Basic", StringComparison.OrdinalIgnoreCase) == 0)
{
string credentials = UTF8Encoding.UTF8.GetString(Convert.FromBase64String(auth.Parameter));
int separatorIndex = credentials.IndexOf(':');
if (separatorIndex >= 0)
{
string email = credentials.Substring(0, separatorIndex);
string password = credentials.Substring(separatorIndex + 1);
//using Facade to get access to database and check credentials
if (//check if valid)
{
Thread.CurrentPrincipal = actionContext.ControllerContext.RequestContext.Principal = new GenericPrincipal(new GenericIdentity(email, "Basic"), System.Web.Security.Roles.Provider.GetRolesForUser(email));
}
}
}
return base.IsAuthorized(actionContext);
}
如果有人可以帮助我,我会很高兴的!