Problem with pdf viewing in IE

G

Guest

Hello to all
I have created an asp.net application that needs to view pdf documents. I ran into a security issue but I added the identity impersonate = true and turned off anonymous access to the site to combat that but now when I run the application instead of the pdf being viewed from IE it prompts me to either open it or download it. When I choose to open it the page opens in notepad and not acrobat. Can anyone think of why this would happen?

Thanks
PatLaf
 
C

Cowboy \(Gregory A. Beamer\)

MIME type on the IIS server is my first guess. When the MIME type is not
set, it will try to download as an unknown file type and make a best guess
as to what program it is opened in. This is a server side issue, not a
client side, unless the client does not have Acrobat.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
PatLaf said:
Hello to all,
I have created an asp.net application that needs to view pdf documents. I
ran into a security issue but I added the identity impersonate = true and
turned off anonymous access to the site to combat that but now when I run
the application instead of the pdf being viewed from IE it prompts me to
either open it or download it. When I choose to open it the page opens in
notepad and not acrobat. Can anyone think of why this would happen?
 
G

Guest

Some things I forgot to mention...The client does have acrobat installed and if I try to open another pdf doc it works.....I'm stumped

Thanks in advance
Patrick Laferriere
 
S

Steven Cheng[MSFT]

Thanks for Cowboy's informative suggestions.

Hi PatLaf,

I think you may try Cowboy's suggestion to have a check on the page's mime
setting to see whether it has been set to the proper value according to pdf
:
application/pdf

If you still feel anything unclear or have any problems, would you please
provide some infos on your page code so as for us to do some further
research? Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

I am posting the code in hopes that someone can help. I don't know why this is happening because it worked the day I built it then on Wednesday last week our network updates took place and now it doesn't. Might be a red herring but I'm not sure....here's the code..

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Clic
Dim sPrefix As String = "WO_
Dim sWildcard As String = "*.pdf
Dim sFilePath As String = ConfigurationSettings.AppSettings("RoutingSheetPath") & "\
Tr
If Not txtWoNum.Text.Length = 10 The
Dim scriptString As String = "<script language=JavaScript> alert('Work Order Number must be 10 digits in length!');</script>
If (Not IsClientScriptBlockRegistered("clientScript")) The
RegisterClientScriptBlock("clientScript", ScriptString
Exit Su
End I
ElseIf Not IsNumeric(txtWoNum.Text.Trim) The
Dim scriptString As String = "<script language=JavaScript> alert('Work Order Number must be numeric!');</script>
If (Not IsClientScriptBlockRegistered("clientScript")) The
RegisterClientScriptBlock("clientScript", ScriptString
Exit Su
End I
End I

Dim sFiles As String() = System.IO.Directory.GetFiles(sFilePath, sPrefix & txtWoNum.Text.Trim & sWildcard

If sFiles.Length > 0 The
'Set the appropriate ContentType
Response.ContentType = "Application/pdf
'Write the file directly to the HTTP output stream
Response.WriteFile(sFiles(0)
'Response.End(
Exit Su
Els
Dim scriptString As String = "<script language=JavaScript> alert('Routing sheet was not found!');</script>
If (Not IsClientScriptBlockRegistered("clientScript")) The
RegisterClientScriptBlock("clientScript", ScriptString
End I
Exit Su
End I

Catch Err As Exceptio
Me.lblWoNum.Visible = Fals
Me.txtWoNum.Visible = Fals
Me.btnSubmit.Visible = Fals
Me.imglogo.visible = Fals
Response.Write(Err.ToString
Dim scriptString As String = "<script language=JavaScript> alert('Unkown error accessing web site!');</script>
If (Not IsClientScriptBlockRegistered("clientScript")) The
RegisterClientScriptBlock("clientScript", ScriptString
Exit Su
End I

End Tr

End Su

THanks in advance,
 
S

Steven Cheng[MSFT]

Hi PatLaf,

Thanks for your followup and the code you provided. From your code I found
that you use
Response.ContentType = "Application/pdf"
Response.WriteFile( filepath) .
to show the pdf to client.
And this code block is called in a button's post back event. I think you
need to first clear all the original headers and content before you set the
Response.ContentType and write the pdf file to the output stream. Also, use
Response.End to endup the Response operation after write file. Here is the
code I used:
----------------------------------------------------
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
If txtFilename.Text.Length > 0 Then
Dim strPath As String
' change the path according to your web folder structure
strPath = Server.MapPath("PDF/") + txtFilename.Text

If System.IO.File.Exists(strPath) Then
'do clear operation
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.ContentType = "Application/pdf"
' add the below sentense if you want to force the client to
open a file open dialog
Response.AddHeader("content-disposition", "attachment;
filename=" + txtFilename.Text)
Response.WriteFile(strPath)
'End the response stream
Response.End()
Else
lblMessage.Text = "Invalid filename!"
End If
Else
lblMessage.Text = "Please enter filename!"
End If
End Sub

----------------------------------------------------
Also, I've attached the whole test page I used on my side which worked
well. You may have a try on it to see if it works on side.

In addition, I've found that you've posted two new thread on this issue and
some other community members and MSFT member have also replied you in
those. Please also have a look to see whether those help. If you have
anything unclear or any further problems, please feel free to post here or
in those threads.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
P

Patrick Laferriere

I copied the code behind page's submit button logic into a new form and
it worked as it should. I don't know why.

Thanks in advance,
PatLaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top