Ask a Question related to ASP.NET Security, Design and Development.
-
rodrigo #1
Secure binary files with ASP.NET and open PDF with Browser
Open Binary files with ASP.Net
Posted: 07-08-2003 05:47 PM
I am trying to protect PDF files with a form that asks the user to
enter name and password.
Basically I created two pages: login.aspx and openpdf.aspx.
Here is the problem.
After authentication, when the script redirects to openpdf.aspx, I
have to hit the refresh button in order for the PDF to open with my
local acrobat reader. PS: I have acrobat installed correctly. Then
after it opens it, I click back and try to access a pdf manually
typing [url]http://localhost/pdf/test.pdf[/url] and it gives me this error with a
messy content.
The server block is not well formed.
Line 3570:r@
Line 3571:1T<ȸѹm
a-߉MKvǀz(j-|BL9~3p.Q3
Line 3572:x*Gn߶dN;|ܛ}6'Ѷ$3'qR< %&4S|qJ~DzR>"ދx/9f
|ʸ'yj= kâٱ ]0'!,ڣp~
ӳq0rN<Qٗc;ޥ`|<\"^\e >PF<?WOcq|"xiorM_a{
"u| = &RK忚6W$dv}*1?X߶i{ #_\Y3Nmc}
Line 3573:6>|d)]";__/9Գ
Line 3574:3%OlOI'
<!=19Gc"&}/>3d,mB=E;bW8{;
Here's my web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.pdf" type="System.Web.UI.PageHandlerFactory" />
</httpHandlers>
<authentication mode="Forms">
<forms name="aspxauth" loginUrl="login.aspx" path="/" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
---------------------This is the validation in login.aspx
--------------------------
private bool ValidateUser(string uid, string passwd)
{
SqlConnection conn;
SqlCommand cmd;
SqlDataReader dr;
conn = new SqlConnection("your connection");
cmd = new SqlCommand("Select * from Sn_RegisteredUsers where
FirstName='" + uid + "'",conn);
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (string.Compare(dr["Pwd"].ToString(),passwd,false)==0)
{
conn.Close();
return true;
}
}
conn.Close();
return false;
}
if (ValidateUser(txtUserName.Value,txtUserPass.Value) )
{
FormsAuthenticationTicket tkt;
string cookiestr;
HttpCookie ck;
tkt = new FormsAuthenticationTicket(1, txtUserName.Value,
DateTime.Now, DateTime.Now.AddMinutes(30), chkPersistCookie.Checked,
"your custom data");
cookiestr = FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
if (chkPersistCookie.Checked)
ck.Expires=tkt.Expiration;
Response.Cookies.Add(ck);
string strRedirect;
//strRedirect = Request["ReturnUrl"];
if (strRedirect==null)
strRedirect = "openpdf.aspx";
Response.Redirect(strRedirect, true);
}
else
Response.Redirect("login.aspx", true);
}
---------------------------- |
-----------------------------------------
-----------------------This is the openpdf.aspx
code------------------------
<%@ Page Language="C#" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath("120-06.pdf");
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
}
</script>
------------------------------- |
---------------------------------------------------
I appreciate any help.
Rod
rodrigo Guest
-
Display Image Binary data in Web Browser
I'm returning the binary data from my webservice and it works but I'm having problems rendering the image in an <img> tag in my web browser. The... -
Can't open administrator, get bunch of binary codesinstead. Please help!
Hello all, I have installed Cold Fusion 6.1 in a Fedora machine and CF admin doesn't want to show up. Instead I see the bunch of characters below.... -
Secure PDF's merged into 1 document from 2 different Secure Files, possible?
I have multiple Secured PDF files that I have created. There is a possibility that my end user will need to merge multiple PDF files into 1 main PDF,... -
Best way to secure binary files
I've got certain report files on my admin section that i'd like to secure. What is the best method of doing this on the web server? These could be... -
How to get a OPEN/SAVE dialog option window when open Excel from IE browser.
I use the following to open Excel from IE browser, but I don't get a OPEN/SAVE dialog option window. Instead, the Excel opened in the browser...



Reply With Quote

