0
我正在使用基本身份验证与SSL,当我调试我的网络API一切似乎工作正常。 IsAuthorized方法被调用,目前工作正常。但是,当我将webapi发布到服务器时,出现以下错误消息已发布的自定义授权属性的问题
发生了错误 。没有连接到Sql数据库。 System.Web.HttpException System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(字符串 fullFileName,DATADIR字符串,字符串的connectionString)
我甚至不知道为什么it's试图创建一个MDF文件,因为webapi正在使用sql server express实例。如果我删除授权属性,一切工作正常。
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);
}
如果有人能帮助我,我会非常高兴!
你能显示它的代码重新实现自定义授权解决了该问题? –
现在添加方法:) – GC268DM
你有任何连接字符串相关的上下文来查找数据库的电子邮件和密码? – Thennarasan