P
phancey
hi,
I'm having an absolute nightmare with this!
I've seen many posts on the subject but still can't quite figure it
out.
I'm using csharp and Framework 1.1.4322.537 on Windows2000 Professional
5.00.2195 Service Pack 4
I click a hyperlink which takes me to an aspx page with a document ID
in the request string. The aspx page checks if there is a doc_id in the
request string. If there is, it looks at a Session variable DataView to
find the location of the document based on the doc_id (don't want users
to see actual location).
Once it has this info, it puts that into another Session Variable and
does a Response.Redirect to the same aspx page but with a user-friendly
request string i.e document=documentType.documentName
On reentry, the page sees this request string, finds the location from
the session variable and uses the following code to serve the PDF file:
if(impersonateValidUser("user", "domain", "password"))
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType="application/pdf";
Response.WriteFile(pdfFile);
Response.Flush();
Response.Close();
undoImpersonation();
}
else
{
}
return;
using the standard MS implementation of impersonation found here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;306158
EXCEPT that I am not doing it in Page_Load.
Code for Page_Load is:
//uses doc_id to identify which document from the dataset is required.
string objectName;
string objectType;
if (Request.QueryString["doc_id"] != null)
{
string docId = Request.QueryString["doc_id"];
System.Data.DataView documents =
(System.Data.DataView)Session["documents"];
if (documents == null)
throw new Exception("You must navigate via the Document Viewer and
select a document first.");
documents.RowFilter="doc_id="+ docId;
//check that there is a document
if (documents.Count==1)
{
objectName = documents[0].Row["object_name"].ToString();
objectType = documents[0].Row["r_object_type"].ToString();
pdfFile = (string)Session["pdfLocation"] +
documents[0].Row["DOCUrl"].ToString();
ArrayList pdfArray = new ArrayList();
pdfArray.Add(pdfFile);
pdfArray.Add(docId);
pdfArray.Add(objectName);
pdfArray.Add(objectType);
Session["pdfArray"] = pdfArray;
string newURL = HttpContext.Current.Request.Path + "?object=" +
objectType + "." + objectName;
Response.Redirect(newURL);
return;
}
else
{
throw new Exception("There is no such document id in the
current dataset.");
}
}
else
{
if (Session["pdfArray"] != null && Request.QueryString["object"] !=
null)
{
if (((ArrayList)Session["pdfArray"]).Count == 4)
{
pdfFile = (string)((ArrayList)Session["pdfArray"])[0];
objectName = (string)((ArrayList)Session["pdfArray"])[2];
objectType = (string)((ArrayList)Session["pdfArray"])[3];
string[] objRequest =
Request.QueryString["object"].Split(".".ToCharArray());
if (objRequest.Length == 2)
{
if (objRequest[0] != objectType || objRequest[1] != objectName)
throw new Exception("This is not a valid document.");
}
else
throw new Exception("This is not a valid document.");
ServePDF();
return;
}
else
{
throw new Exception("This is not a valid document.");
}
}
else
{
throw new Exception("This is not a valid document.");
}
}
string pdfFile is a class variable.
Now, this code works fine for 3 of my documents which are under 200kb
but the one that is 3822KB fails with the error message Server
Application Unavailable and the event log says aspnet_wp.exe stopped
unexpectedly.
The machine.config is set to use SYSTEM (though with Framework 1.1 I
don't think this should be necessary, and indeed it may not be - have
now tested "machine" and that seems to work the same). The httpRuntime
MaxRequestLength in machine.config was 4096 and since this was close I
upped it to 8192 but that didn't fix it. This setting is not overridden
in the web.config file.
What may give the game away (but not to me!) is that the Page_Load is
triggerred 3 times instead of the 2 I was expecting. Once with the
doc_id, then after the Redirect but then a third time??? Presumably
something to do with the Response.Flush or Response.Close...
Can anyone help me? Even more frustrating is that I actually had this
big file working occasionally yesterday though it would randomly cause
this error message. However, after my tinkering it always produces the
error now ( (only for the large file).
thanks
Phil
I'm having an absolute nightmare with this!
I've seen many posts on the subject but still can't quite figure it
out.
I'm using csharp and Framework 1.1.4322.537 on Windows2000 Professional
5.00.2195 Service Pack 4
I click a hyperlink which takes me to an aspx page with a document ID
in the request string. The aspx page checks if there is a doc_id in the
request string. If there is, it looks at a Session variable DataView to
find the location of the document based on the doc_id (don't want users
to see actual location).
Once it has this info, it puts that into another Session Variable and
does a Response.Redirect to the same aspx page but with a user-friendly
request string i.e document=documentType.documentName
On reentry, the page sees this request string, finds the location from
the session variable and uses the following code to serve the PDF file:
if(impersonateValidUser("user", "domain", "password"))
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType="application/pdf";
Response.WriteFile(pdfFile);
Response.Flush();
Response.Close();
undoImpersonation();
}
else
{
}
return;
using the standard MS implementation of impersonation found here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;306158
EXCEPT that I am not doing it in Page_Load.
Code for Page_Load is:
//uses doc_id to identify which document from the dataset is required.
string objectName;
string objectType;
if (Request.QueryString["doc_id"] != null)
{
string docId = Request.QueryString["doc_id"];
System.Data.DataView documents =
(System.Data.DataView)Session["documents"];
if (documents == null)
throw new Exception("You must navigate via the Document Viewer and
select a document first.");
documents.RowFilter="doc_id="+ docId;
//check that there is a document
if (documents.Count==1)
{
objectName = documents[0].Row["object_name"].ToString();
objectType = documents[0].Row["r_object_type"].ToString();
pdfFile = (string)Session["pdfLocation"] +
documents[0].Row["DOCUrl"].ToString();
ArrayList pdfArray = new ArrayList();
pdfArray.Add(pdfFile);
pdfArray.Add(docId);
pdfArray.Add(objectName);
pdfArray.Add(objectType);
Session["pdfArray"] = pdfArray;
string newURL = HttpContext.Current.Request.Path + "?object=" +
objectType + "." + objectName;
Response.Redirect(newURL);
return;
}
else
{
throw new Exception("There is no such document id in the
current dataset.");
}
}
else
{
if (Session["pdfArray"] != null && Request.QueryString["object"] !=
null)
{
if (((ArrayList)Session["pdfArray"]).Count == 4)
{
pdfFile = (string)((ArrayList)Session["pdfArray"])[0];
objectName = (string)((ArrayList)Session["pdfArray"])[2];
objectType = (string)((ArrayList)Session["pdfArray"])[3];
string[] objRequest =
Request.QueryString["object"].Split(".".ToCharArray());
if (objRequest.Length == 2)
{
if (objRequest[0] != objectType || objRequest[1] != objectName)
throw new Exception("This is not a valid document.");
}
else
throw new Exception("This is not a valid document.");
ServePDF();
return;
}
else
{
throw new Exception("This is not a valid document.");
}
}
else
{
throw new Exception("This is not a valid document.");
}
}
string pdfFile is a class variable.
Now, this code works fine for 3 of my documents which are under 200kb
but the one that is 3822KB fails with the error message Server
Application Unavailable and the event log says aspnet_wp.exe stopped
unexpectedly.
The machine.config is set to use SYSTEM (though with Framework 1.1 I
don't think this should be necessary, and indeed it may not be - have
now tested "machine" and that seems to work the same). The httpRuntime
MaxRequestLength in machine.config was 4096 and since this was close I
upped it to 8192 but that didn't fix it. This setting is not overridden
in the web.config file.
What may give the game away (but not to me!) is that the Page_Load is
triggerred 3 times instead of the 2 I was expecting. Once with the
doc_id, then after the Redirect but then a third time??? Presumably
something to do with the Response.Flush or Response.Close...
Can anyone help me? Even more frustrating is that I actually had this
big file working occasionally yesterday though it would randomly cause
this error message. However, after my tinkering it always produces the
error now ( (only for the large file).
thanks
Phil