1

因此,我正在尝试使用服务器,并且正在将网站从旧服务器移动到新服务器。它正在从 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

版本

4

1 回答 1

2

我的错误和你的非常相似。原来,我们使用的应用程序是在 64 位服务器上使用的 32 位 dll。

IIS 中的应用程序池设置为不运行 32 位 dll。

在我看来,这可能是由于 32-64 位开关。

于 2012-04-18T07:33:32.990 回答