Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Monday, March 26, 2012

How to show a stored PDF

New to asp and have no idea what I'm doing wrong here. I just want to open a pdf that I have stored in a table and show it on the page. Here is my code. I keep getting theSystem.NullReferenceException was unhandled by user code.

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:smithsdaConnectionStringtest %>"

ProviderName="<%$ ConnectionStrings:smithsdaConnectionStringtest.ProviderName %>"

SelectCommand="SELECT * FROM [correspondence] WHERE ([facilitiesID] = ?)">

<SelectParameters>

<asp:QueryStringParameterName="facilitiesID"QueryStringField="DACorr"Type="Int32"/>

</SelectParameters>

</asp:SqlDataSource>

<scriptrunat="server">

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

Dim ScanDocAsNew DataViewDim argAsNew DataSourceSelectArguments

ScanDoc = SqlDataSource1.Select(arg)

Dim ScanLet(1)AsByte

ScanLet(0) =CByte(ScanDoc(0)("Letter"))

If ScanDocIsNot""Then

Response.Buffer =True

Response.Clear()

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType ="application/pdf"

Response.BinaryWrite(ScanLet)

Response.End()

EndIf

EndSub

</script

Any Help greatly appreciated.

My suggestion would be to store the PDF files, all in one directory, then, in the database, store the names of the PDF files.

Then, show the relevant information in the database, using a Gridview, including one TemplateField, which would have a Hyperlink to the folder where the pDFs are stored, and the PDF itself. Then, when people clicked on the hyperlink, the PDF would show

|||

David,

Thanks for the reply. I wish I could do it that way, unfortunately they want the pdfs stored in the database so noone can accidentally delete them. The db has probably 200 stored pdfs associated with records and they need to be able to pull them up for viewing.

Thanks,

DeWayne

|||

I've changed the code to this and now it just opens a blank web page.

Dim ScanDocAsNew DataViewDim argAsNew DataSourceSelectArguments

ScanDoc = SqlDataSource1.Select(arg)

Dim ScanLet(1)AsByte

ScanLet(0) =CByte(Request.QueryString("Letter"))

If ScanDocIsNot""Then

Response.Buffer =True

Response.Clear()

Response.ClearContent()

Response.ClearHeaders()

'Response.AddHeader("content-disposition", "inline;filename=" + ScanLet)

Response.ContentType ="application/pdf"

'Response.AppendHeader("content-disposition", "inline;filename=" + "Scan.PDF")

Response.BinaryWrite(ScanLet)

Response.End()

'Else

' Response.Write("Error")

EndIf

I think I am on the right track but no PDF file yet.

|||

I finally got it, thanks to reading other posts in the forum and especially the one from adam v on how to strip the ole header. Now I just have to deal with .doc and .tif headers. This is a great forum and I have found lots of useful tips and tricks in here.

Thanks.

Here is the code I ended up with...

myConnection.Open()Dim myDataReaderAs OleDbDataReader = myCommand.ExecuteReader() myDataReader.Read()Dim intLoopCountAs Integer Dim intPositionAs Integer Dim ScanLetAs Byte() = myDataReader("letter")Do While intLoopCount < ScanLet.LengthIf ScanLet(intLoopCount) = 37Then'%If ScanLet(intLoopCount + 1) = 80Then'PIf ScanLet(intLoopCount + 2) = 68Then'DIf ScanLet(intLoopCount + 3) = 70Then'FIf ScanLet(intLoopCount + 4) = 45Then'- intPosition = intLoopCount intLoopCount = ScanLet.LengthEnd If End If End If End If End If intLoopCount = intLoopCount + 1Loop Dim bytStrippedData(ScanLet.Length - intPosition - 1)As Byte System.Buffer.BlockCopy(src:=ScanLet, srcOffset:=intPosition, dst:=bytStrippedData, dstOffset:=0, count:=ScanLet.Length - intPosition) Response.Clear() Response.ClearContent() Response.ClearHeaders() Response.ContentType ="application/pdf" Response.BinaryWrite(bytStrippedData) Response.Flush() Response.End() myConnection.Close() Response.Write("Person info successfully retrieved!")End UsingEnd Sub

Monday, March 19, 2012

How to set up connection to MS SQL remotely

If I let the pages (ASP) running on the third party server access my database (MS SQL) remotely, what should I do with my database server? I was told to open a port. If it is true, what is the number of the port I should open?
Thanks in advanceDANGER. Be careful. If you do this wrong you can open up your server for the world to access.

The default port is 1433, but if you are going to do this I reccomend changing that. You are also going to have to do stuff with your firewall. This is very dangerous and I would reccomend you explore other options. I imagine the peformance of the pages are going to suck as well.|||If you, against all advices, should decide to do this, you should definitely have a look at HTTP endpoints, and see if you could use a HTTP endpoint. If so, you should open ONE port (443) from ONE ip (the webserver) for ONE user, which authenticates using a rather secure method, as for instance a certificate.

This is the only solution I would think of that could come into consideration.

How to set this up?

I need to set up the security on the Reporting Services such that user can
view the reports ONLY through a ReportViewer control on a asp.net web page
ie not allow to navigate all other folders or areas in the Report Manager.
Reporting services is installed on a stand alone server (not belong to any
domain, no AD set up) running on Windows 2003 server. Currently I configured
the "Report Manager" and "ReportServer" web site to allow annonyous access.
However some users know how to bypass the web application and directly enter
the IP address/reports of the stand alone server to view all the reports.
The asp.net page has built-in security to filter out the reports listed on
the page based on the user login and password. This web application is also
hosted at the stand alone server and is connected to a remote Sql server.
The web application is using the sql security.I have a similar problem and cannot find a solution provided by Microsoft.
However, I decidee to solve it by a trick. I develop an ASP.net web
application and the application have some report printing function. Whenever
a report is printed, a random key will be inserted into a database table
like this:
Key User
KE#n-asdfjk-ad33klj-kasjd WBush
The key and user are also passed in the query string. When the report is
run, the key and user will be checked again in the stored procedure to
verify that this user can print this report.
I am not sure whether this is a good solution, but I think that's what we
can do before Microsoft can provide a better solution.
"Paul" <paul_mak@.hotmail.com> wrote in message
news:eWZLuvhdGHA.2456@.TK2MSFTNGP04.phx.gbl...
> I need to set up the security on the Reporting Services such that user can
> view the reports ONLY through a ReportViewer control on a asp.net web page
> ie not allow to navigate all other folders or areas in the Report Manager.
> Reporting services is installed on a stand alone server (not belong to any
> domain, no AD set up) running on Windows 2003 server. Currently I
configured
> the "Report Manager" and "ReportServer" web site to allow annonyous
access.
> However some users know how to bypass the web application and directly
enter
> the IP address/reports of the stand alone server to view all the reports.
> The asp.net page has built-in security to filter out the reports listed on
> the page based on the user login and password. This web application is
also
> hosted at the stand alone server and is connected to a remote Sql server.
> The web application is using the sql security.
>|||Hi Paul.
The only way I know of is to have your web site's app pool use an identity
that is the only identity that is allowed to hit the reports.
For example, you might set up a service account called "WebApp1SvcAcct".
give that account and administrators group privileges in reporting services,
but not the rest of your users. This might be only half the solution. It's
been a while since we've had to deal with this.
-Tim
"Paul" <paul_mak@.hotmail.com> wrote in message
news:eWZLuvhdGHA.2456@.TK2MSFTNGP04.phx.gbl...
>I need to set up the security on the Reporting Services such that user can
>view the reports ONLY through a ReportViewer control on a asp.net web page
>ie not allow to navigate all other folders or areas in the Report Manager.
>Reporting services is installed on a stand alone server (not belong to any
>domain, no AD set up) running on Windows 2003 server. Currently I
>configured the "Report Manager" and "ReportServer" web site to allow
>annonyous access. However some users know how to bypass the web application
>and directly enter the IP address/reports of the stand alone server to view
>all the reports. The asp.net page has built-in security to filter out the
>reports listed on the page based on the user login and password. This web
>application is also hosted at the stand alone server and is connected to a
>remote Sql server. The web application is using the sql security.
>

Friday, March 9, 2012

How to set my ASP.NET application to access SQL Server 2005 using clients user credentials

Hi guys,

I'm not sure if I'm just bad at googling but I can't seem to find a way to set an ASP.NET 2.0 web application to connect to SQL Server 2005 using the current client's user credentials. My web application is using Integrated Windows Authentication so its Page.User.Identity is set to a DOMAIN\username value... I want to pass that to my connectionstring or have my connections pick up the identity automatically and use that Identity when accessing the db server.

Oh and another thing, my IIS Application Pool is using a specific Identity itself, so I don't know if that might affect the above.

Hope someone could help.

Hi,

what you need is process impersonation, that allows asp.net to switch the execute owner to an other user. I have used this for asp.net and remoting calls, so that i have the original caller. I have two links for you:

http://msdn2.microsoft.com/en-us/library/ms998292.aspx|||Thanks Zhou. I'll the articles out once I get my hands on our dev server.Stick out tongue Thanks.