为什么我使用针对 Azure SQL 的 OWIN 身份验证会收到 "The magic number in GZip header is not correct." 错误
Why am I getting "The magic number in GZip header is not correct." error using OWIN auth against Azure SQL
Google 或 SO 上没有任何内容与此特定问题相关,因此提出一个新问题。我使用标准 user-security 选项创建了一个全新的 Asp.Net MVC Web Application。我还在 Azure 中创建了一个空数据库。
除了将默认连接字符串更改为以下内容外,我什么也没做:
<connectionStrings>
<add name="DefaultConnection"
connectionString="data source=mydatabase.database.windows.net;initial catalog=Feedback;persist security info=True;user id=LeaveFeedbackuser;password=mypassword;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
和默认的连接工厂:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
在尝试注册时(当我希望它正常创建 AspNetUsers
和相关表时)我收到以下错误:
The magic number in GZip header is not correct. Make sure you are
passing in a GZip stream. Description: An unhandled exception
occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.IO.InvalidDataException: The magic number
in GZip header is not correct. Make sure you are passing in a GZip
stream.
Source Error:
Line 153: { Line 154: var user = new
ApplicationUser { UserName = model.Email, Email = model.Email }; Line
155: var result = await UserManager.CreateAsync(user,
model.Password); Line 156: if (result.Succeeded) Line
157: {
这与 GZip 有什么关系,是什么导致了这个错误?这几天让我无法让 OWIN 使用我的 Azure 数据库。
这是我的 "theory"。我认为 Sql Azure Db 设置不正确或连接字符串有误。
我们知道,当 AspIdentity 尝试在登录时访问数据库并发现表未设置时,它将尝试创建它们。
我认为 AspIdentity 代码中有一个 breakdown/bug 在这种情况下吞没了错误连接字符串生成的异常,从而导致设置失败,并继续以愉快的方式尝试提供身份验证票证客户。
如果我们查看 Microsoft.Owin.Security.DataHandler.Serializer.TicketSerializer 的代码,我们会发现一些 GZip 操作:
public virtual byte[] Serialize(AuthenticationTicket model)
{
using (var memory = new MemoryStream())
{
using (var compression = new GZipStream(memory, CompressionLevel.Optimal))
{
using (var writer = new BinaryWriter(compression))
{
Write(writer, model);
}
}
return memory.ToArray();
}
}
所以基本上我认为 AspIdentity 在连接上失败,这个错误被吞噬了,Owin 管道继续处理请求但是当它到达 TicketSerializer
时可能传递了一个空值或其他一些虚假值Gzip 尝试压缩和 Boom!
奇怪的 YSOD 输出随之而来。
The magic number in GZip header is not correct. Make sure you are
passing in a GZip stream. Description: An unhandled exception occurred
during the execution of the current web request. Please review the
stack trace for more information about the error and where it
originated in the code.
AspIdentity 没有正确短路针对此特定事件的 OWIN 请求处理。
可能完全是胡说八道,但我还是会把它扔在那里。
我遇到了类似的问题。
Entity Framework __MigrationHistory
Model
列包含 GZip 压缩数据。如果此列中的数据已损坏,则您的应用将无法解压缩数据,您将收到错误消息。
在我的例子中,损坏是通过尝试手动插入到这个 able 中发生的。
我的解决方案:删除损坏的 __MigrationHistory
行和相关的数据库更改,并允许应用正确迁移数据库。
Google 或 SO 上没有任何内容与此特定问题相关,因此提出一个新问题。我使用标准 user-security 选项创建了一个全新的 Asp.Net MVC Web Application。我还在 Azure 中创建了一个空数据库。
除了将默认连接字符串更改为以下内容外,我什么也没做:
<connectionStrings>
<add name="DefaultConnection"
connectionString="data source=mydatabase.database.windows.net;initial catalog=Feedback;persist security info=True;user id=LeaveFeedbackuser;password=mypassword;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
和默认的连接工厂:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
在尝试注册时(当我希望它正常创建 AspNetUsers
和相关表时)我收到以下错误:
The magic number in GZip header is not correct. Make sure you are passing in a GZip stream. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.InvalidDataException: The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.
Source Error:
Line 153: { Line 154: var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; Line 155: var result = await UserManager.CreateAsync(user, model.Password); Line 156: if (result.Succeeded) Line 157: {
这与 GZip 有什么关系,是什么导致了这个错误?这几天让我无法让 OWIN 使用我的 Azure 数据库。
这是我的 "theory"。我认为 Sql Azure Db 设置不正确或连接字符串有误。
我们知道,当 AspIdentity 尝试在登录时访问数据库并发现表未设置时,它将尝试创建它们。
我认为 AspIdentity 代码中有一个 breakdown/bug 在这种情况下吞没了错误连接字符串生成的异常,从而导致设置失败,并继续以愉快的方式尝试提供身份验证票证客户。
如果我们查看 Microsoft.Owin.Security.DataHandler.Serializer.TicketSerializer 的代码,我们会发现一些 GZip 操作:
public virtual byte[] Serialize(AuthenticationTicket model)
{
using (var memory = new MemoryStream())
{
using (var compression = new GZipStream(memory, CompressionLevel.Optimal))
{
using (var writer = new BinaryWriter(compression))
{
Write(writer, model);
}
}
return memory.ToArray();
}
}
所以基本上我认为 AspIdentity 在连接上失败,这个错误被吞噬了,Owin 管道继续处理请求但是当它到达 TicketSerializer
时可能传递了一个空值或其他一些虚假值Gzip 尝试压缩和 Boom!
奇怪的 YSOD 输出随之而来。
The magic number in GZip header is not correct. Make sure you are passing in a GZip stream. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
AspIdentity 没有正确短路针对此特定事件的 OWIN 请求处理。
可能完全是胡说八道,但我还是会把它扔在那里。
我遇到了类似的问题。
Entity Framework __MigrationHistory
Model
列包含 GZip 压缩数据。如果此列中的数据已损坏,则您的应用将无法解压缩数据,您将收到错误消息。
在我的例子中,损坏是通过尝试手动插入到这个 able 中发生的。
我的解决方案:删除损坏的 __MigrationHistory
行和相关的数据库更改,并允许应用正确迁移数据库。