从新服务器上的图像字段生成 PDF
因此,我正在尝试一台服务器,并将网站从旧服务器移动到新服务器。它正在从 32 位变为 64 位。开发人员(已不在此处)对网站进行了编码,以上传 PDF 文档并将其保存在图像字段中。效果很好,但在新服务器上不行。
以下代码是调用以显示 PDF 的页面。例如: TestMethod.aspx?id=75
<%@ Page language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.Buffer = true;
SqlCommand cmd = new SqlCommand("SELECT method FROM Tests WHERE id = @id");
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Int32.Parse(Request["id"]);
Util.GetBLOB(cmd, Response.OutputStream, 32768);
Response.Flush();
Response.End();
}
</script>
GetBLOB 函数如下:
public static void GetBLOB(SqlCommand cmd, Stream output, int bufferLength)
{
byte[] outbytes = new byte[bufferLength];
SqlConnection connex = new SqlConnection(ConfigurationSettings.AppSettings["DSN"]);
cmd.Connection = connex;
connex.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
rdr.Read();
int start = 0;
long retval = rdr.GetBytes(0, 0, null, 0, 0);
retval = rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
while (retval > 0)
{
output.Write(outbytes, 0, (int)retval);
start += outbytes.Length;
retval = rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
}
retval = rdr.GetBytes(0, start, null, 0, 0);
outbytes = new byte[retval];
rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
output.Write(outbytes, 0, (int)retval);
connex.Close();
}
我对 ASP.NET 很陌生,看不到简单的解决方案。这和服务器是 64 位有什么关系吗?感谢您的任何帮助。
运行时出现以下错误:
Specified argument was out of the range of valid values.
Parameter name: offset
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.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: offset
Source Error:
Line 14: SqlCommand cmd = new SqlCommand("SELECT document FROM TechLibrary WHERE id = @id");
Line 15: cmd.Parameters.Add("@id", SqlDbType.Int).Value = Int32.Parse(Request["id"]);
Line 16: Util.GetBLOB(cmd, Response.OutputStream, 32768);
Line 17:
Line 18: Response.Flush();
Source File: d:\....\TechLibraryDoc.aspx Line: 16
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: offset]
System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count) +169
trace.Util.GetBLOB(SqlCommand cmd, Stream output, Int32 bufferLength) in c:\Inetpub\wwwroot\trace\src\Util.cs:146
ASP.techlibrarydoc_aspx.Page_Load(Object sender, EventArgs e) in d:\.....\TechLibraryDoc.aspx:16
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2603
版本
So, I'm trying to a server and I'm moving a website from an older server to a new one. It's changing from 32-bit to 64-bit. The developer (who is no longer here) coded the webstie to upload PDF documents and save them in an Image field. Works great, but not on the new server.
The following code is the page that gets called to display the PDF. Ex: TestMethod.aspx?id=75
<%@ Page language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.Buffer = true;
SqlCommand cmd = new SqlCommand("SELECT method FROM Tests WHERE id = @id");
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Int32.Parse(Request["id"]);
Util.GetBLOB(cmd, Response.OutputStream, 32768);
Response.Flush();
Response.End();
}
</script>
The GetBLOB function is as follows:
public static void GetBLOB(SqlCommand cmd, Stream output, int bufferLength)
{
byte[] outbytes = new byte[bufferLength];
SqlConnection connex = new SqlConnection(ConfigurationSettings.AppSettings["DSN"]);
cmd.Connection = connex;
connex.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
rdr.Read();
int start = 0;
long retval = rdr.GetBytes(0, 0, null, 0, 0);
retval = rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
while (retval > 0)
{
output.Write(outbytes, 0, (int)retval);
start += outbytes.Length;
retval = rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
}
retval = rdr.GetBytes(0, start, null, 0, 0);
outbytes = new byte[retval];
rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
output.Write(outbytes, 0, (int)retval);
connex.Close();
}
I am very new to ASP.NET and cannot see a simple solution. Does this have anything to do with the server being 64 bit? Thanks for any help.
I get the following error when run:
Specified argument was out of the range of valid values.
Parameter name: offset
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.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: offset
Source Error:
Line 14: SqlCommand cmd = new SqlCommand("SELECT document FROM TechLibrary WHERE id = @id");
Line 15: cmd.Parameters.Add("@id", SqlDbType.Int).Value = Int32.Parse(Request["id"]);
Line 16: Util.GetBLOB(cmd, Response.OutputStream, 32768);
Line 17:
Line 18: Response.Flush();
Source File: d:\....\TechLibraryDoc.aspx Line: 16
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: offset]
System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count) +169
trace.Util.GetBLOB(SqlCommand cmd, Stream output, Int32 bufferLength) in c:\Inetpub\wwwroot\trace\src\Util.cs:146
ASP.techlibrarydoc_aspx.Page_Load(Object sender, EventArgs e) in d:\.....\TechLibraryDoc.aspx:16
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2603
Version
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的错误与你的非常相似。原来我们使用的应用程序是在 64 位服务器上使用的 32 位 dll。
IIS 中的应用程序池设置为不运行 32 位 dll。
在我看来,这可能是由于 32-64 位开关所致。
My error was very similar to yours. it turned out that the app we were using was a 32 bit dll used on the 64 bit server.
The app pool in IIS was set to not run 32 bit dlls.
in my opinion, its probably due to the 32-64 bit switch.