[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

.htaccess  (403) Forbidden vb.net file download

Posted on 2006-03-30
9
Medium Priority
?
541 Views
Last Modified: 2008-01-09
hi
i try to download a file from the server, the folder that withhold the file contain this file: .htaccess
inside of it there is: deny from all

im trying to access this folder using this code:

 Try
            Dim proxyObject As WebProxy = New WebProxy(url, True)
            Dim objRequest As WebRequest = System.Net.HttpWebRequest.Create(url)
            objRequest.Proxy = proxyObject
            Dim ws As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
            Dim str As Stream = ws.GetResponseStream()
            ................
            ................
this is returning the exception:
The remote server returned an error: (403) Forbidden.
is there a way to download the file without having to remove the .htaccess ???
thanks in advcance
 
0
Comment
Question by:mte01
  • 6
  • 3
9 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 16332108
Hi mte01,

Simply put, NO.

The .htaccess file determines who can access what files within the folder and do what with them. If it is set to deny from all then there is nothing you can do with it.

Tim Cottee
0
 
LVL 3

Author Comment

by:mte01
ID: 16332198
Hi Tim
humm not cool :(
can i change the .htaccess file in such way that only my .net application can access the folder?
Best
0
 
LVL 3

Author Comment

by:mte01
ID: 16332270
Note that I have control over this .htaccess file, and what I want is to change it so that it allows only my .net application to access this folder..any help on that??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Accepted Solution

by:
TimCottee earned 1500 total points
ID: 16332415
mte01,

Hmm, you could perhaps do this:

        Dim proxyObject As WebProxy = New WebProxy(url, True)
        Dim objRequest As HttpWebRequest = System.Net.HttpWebRequest.Create(url)
        objRequest.Referer = "SomeSpecificDomain.Com"
        objRequest.Proxy = proxyObject
        Dim ws As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
        Dim str As Stream = ws.GetResponseStream()

Then in the .htaccess file do:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?SomeSpecificDomain.com/.*$ [NC]
RewriteRule \.xxx$ - [F]

Assuming that the file has a .xxx extension in this case.

What this will do is essentially the same as you have with sites that do not allow hot-linking of images, if you attempt to get that file (xxxx.xxx) from the folder with a referer that doesn't match the one supplied then it will give you a 404 error. If it does match (and you can be as awkward as you like in specifying the referer here) then it will be allowed access to the file.

Perhaps not a 100% solution but no reason why it cannot work.

Tim
0
 
LVL 3

Author Comment

by:mte01
ID: 16333129
sorry Tim, but this didnt work, when i tried the call the url from explorer i got this error:
" Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log. "

when i tried it from my vb.net application i got this exception:
" The remote server returned an error: (500) Internal Server Error. "

i have changed the
RewriteRule \.xxx$ - [F] to RewriteRule \.exe$ - [F]
and i kept this line as it is for i dont know which domain shall i put:
objRequest.Referer = "SomeSpecificDomain.Com"

thanks for the help
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 16333220
mte01,

It may be that this is actually because it is working and the settings are not quite right.

I have given you objRequest.Referer="SomeSpecificDomain.Com" but in .htaccess the condition includes http:// as well so we need to modify one or the other.

Try it with

objRequest.Referer="http://SomeSpecificDomain.com"

If it works then your app will be fine as it is passing in the same referer as the .htaccess file is expecting but anyone else who will not have that same referer value will get a failure page as you have done.
Tim
0
 
LVL 3

Author Comment

by:mte01
ID: 16339946
Tim,
 Actually the problem is that I don't know what I should place instead of this SomeSpecifcDomain.com in the case of my application.
0
 
LVL 3

Author Comment

by:mte01
ID: 16339986
I figured out now that it can be anything as long as it's the same on both sides, I tried your latest suggestion, and it also didn't work....
0
 
LVL 3

Author Comment

by:mte01
ID: 16343581
I solved it using another way...thanks for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question