473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Deny access to htm files

I have a web application using forms authentication and everything seemed to
be working fine, as far as requiring them to login.

But then I noticed that you could type in:
http://domain.com/restrictefolder/test.htm

How do I deny access to a folder full of .htm files that I don't want them
to read unless they have logged in?
Nov 19 '05 #1
7 2352
Hi,

How long are you persisting the cookie for Forms Authentication. The said
url is accessible because within a browser session, the cookie still exist.
Try calling FormsAuthentication.Signout() in the initial Page_Load before
you redirect to your login page.

Hope that helps.

Joyjit

"Brian Linden" <br***@ineedadip.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I have a web application using forms authentication and everything seemed to be working fine, as far as requiring them to login.

But then I noticed that you could type in:
http://domain.com/restrictefolder/test.htm

How do I deny access to a folder full of .htm files that I don't want them
to read unless they have logged in?

Nov 19 '05 #2
Well as Joyjit adviced that should work for you!
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3
My *guess* would be that, because these files are normal, static, html
files, the ASP.NET engine isn't getting anywhere near them.

I wonder what would happen if you add the .htm extension to your IIS
config, to be processed through ASP.NET (you would also need to add a
handler - wonder how Page Handler would react to a plain htm file).

That would be the direction I would look in. Should be a change to IIS
and a change to machine.config.

Nov 19 '05 #4
Brian, I'm reading your question a little differently than Joyit and
Patrick, so I'll comment in case it helps.

If I understand your question, you'd like to know how to ensure that a
request for a .htm file forces a Forms Authentication login in the same way
that a request for a .aspx file does.

When a Url request is processed by IIS, a decision is made regarding who
gets to process it. This is done (rather frustratingly) based on the
extension of the Url.

Files ending in ".aspx" are processed by .NET, while other files like
".gif", ".jpeg", ".html" are processed directly by IIS.

Because Forms Authentication is a .NET feature, requests that bypass .NET
are not covered by the Forms Authentication security scheme.

As usual, there are a number of ways to handle this but the easiest way is
to make a list of all the file types you want protected by Forms
Authentication, and then configure IIS to pass all of these through .NET.

In the IIS Manager;

+ Pick your website
+ Right-click, properties; the property dialog appears
+ Select the "Home Directory" tab
+ Click the "Configuration" button; the "Application Configuration" dialog
appears
+ Select the "Mappings" tab

You'll see a list of Application extensions, with mappings to specific
handlers. For example,

".aspx" is mapped to;
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspne t_isapi.dll

Check yours, it will contain the correct path to the aspnet_isapi.dll, which
is what you want.

Now go to all of the file types you need, such as .htm, .gif, .jpeg, .jpg,
and Edit their mappings to the same value. You may need to Add some entries
for certain file types as well.

Cheers,

/// M


"Brian Linden" <br***@ineedadip.com> wrote in message
news:#n**************@TK2MSFTNGP12.phx.gbl...
I have a web application using forms authentication and everything seemed to be working fine, as far as requiring them to login.

But then I noticed that you could type in:
http://domain.com/restrictefolder/test.htm

How do I deny access to a folder full of .htm files that I don't want them
to read unless they have logged in?

Nov 19 '05 #5
That is exactly what I meant.

Thank you,
That is exactly what I was looking for....BUT...
A .htm file was an example that I thought I could post and take the solution
and apply that
everywhere...but the majority of the files that I am trying to protect are
..asp files. And those already have an ISAP filter associated with it.

Can you think of a way to protect those?

"MWells" <outbound__at_sygnal.com> wrote in message
news:ek****************@TK2MSFTNGP09.phx.gbl...
Brian, I'm reading your question a little differently than Joyit and
Patrick, so I'll comment in case it helps.

If I understand your question, you'd like to know how to ensure that a
request for a .htm file forces a Forms Authentication login in the same way that a request for a .aspx file does.

When a Url request is processed by IIS, a decision is made regarding who
gets to process it. This is done (rather frustratingly) based on the
extension of the Url.

Files ending in ".aspx" are processed by .NET, while other files like
".gif", ".jpeg", ".html" are processed directly by IIS.

Because Forms Authentication is a .NET feature, requests that bypass .NET
are not covered by the Forms Authentication security scheme.

As usual, there are a number of ways to handle this but the easiest way is
to make a list of all the file types you want protected by Forms
Authentication, and then configure IIS to pass all of these through .NET.

In the IIS Manager;

+ Pick your website
+ Right-click, properties; the property dialog appears
+ Select the "Home Directory" tab
+ Click the "Configuration" button; the "Application Configuration" dialog appears
+ Select the "Mappings" tab

You'll see a list of Application extensions, with mappings to specific
handlers. For example,

".aspx" is mapped to;
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspne t_isapi.dll

Check yours, it will contain the correct path to the aspnet_isapi.dll, which is what you want.

Now go to all of the file types you need, such as .htm, .gif, .jpeg, .jpg,
and Edit their mappings to the same value. You may need to Add some entries for certain file types as well.

Cheers,

/// M


"Brian Linden" <br***@ineedadip.com> wrote in message
news:#n**************@TK2MSFTNGP12.phx.gbl...
I have a web application using forms authentication and everything seemed
to
be working fine, as far as requiring them to login.

But then I noticed that you could type in:
http://domain.com/restrictefolder/test.htm

How do I deny access to a folder full of .htm files that I don't want

them to read unless they have logged in?


Nov 19 '05 #6
Unfortunately I don't; I've never tried mixing classic ASP and ASP.NET to
any meaningful extent. The idea of securing classic ASP using Forms
Authentication is probably a unique case; you might try a new post specific
to that scenario.

/// M

"Brian Linden" <br***@ineedadip.com> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
That is exactly what I meant.

Thank you,
That is exactly what I was looking for....BUT...
A .htm file was an example that I thought I could post and take the solution and apply that
everywhere...but the majority of the files that I am trying to protect are
.asp files. And those already have an ISAP filter associated with it.

Can you think of a way to protect those?

"MWells" <outbound__at_sygnal.com> wrote in message
news:ek****************@TK2MSFTNGP09.phx.gbl...
Brian, I'm reading your question a little differently than Joyit and
Patrick, so I'll comment in case it helps.

If I understand your question, you'd like to know how to ensure that a
request for a .htm file forces a Forms Authentication login in the same

way
that a request for a .aspx file does.

When a Url request is processed by IIS, a decision is made regarding who
gets to process it. This is done (rather frustratingly) based on the
extension of the Url.

Files ending in ".aspx" are processed by .NET, while other files like
".gif", ".jpeg", ".html" are processed directly by IIS.

Because Forms Authentication is a .NET feature, requests that bypass ..NET
are not covered by the Forms Authentication security scheme.

As usual, there are a number of ways to handle this but the easiest way is to make a list of all the file types you want protected by Forms
Authentication, and then configure IIS to pass all of these through ..NET.
In the IIS Manager;

+ Pick your website
+ Right-click, properties; the property dialog appears
+ Select the "Home Directory" tab
+ Click the "Configuration" button; the "Application Configuration"

dialog
appears
+ Select the "Mappings" tab

You'll see a list of Application extensions, with mappings to specific
handlers. For example,

".aspx" is mapped to;
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspne t_isapi.dll

Check yours, it will contain the correct path to the aspnet_isapi.dll,

which
is what you want.

Now go to all of the file types you need, such as .htm, .gif, .jpeg, ..jpg, and Edit their mappings to the same value. You may need to Add some

entries
for certain file types as well.

Cheers,

/// M


"Brian Linden" <br***@ineedadip.com> wrote in message
news:#n**************@TK2MSFTNGP12.phx.gbl...
I have a web application using forms authentication and everything

seemed
to
be working fine, as far as requiring them to login.

But then I noticed that you could type in:
http://domain.com/restrictefolder/test.htm

How do I deny access to a folder full of .htm files that I don't want

them to read unless they have logged in?



Nov 19 '05 #7

Original message:
Thank you,
That is exactly what I was looking for....BUT...
A .htm file was an example that I thought I could post and take the
solution and apply that everywhere...
but the majority of the files that I am trying to protect are .asp
files.
And those already have an ISAP filter associated with it.
Can you think of a way to protect those?
--------------------
my response:

In order to protect .asp files on my .net website:
- I coded my login form so it sets a session variable to "True"
- I coded global.asa so it checks this session variable, and transfers
control to the login form if the variable hasn't been set.

Here is the code in my login form:
private void ButtonLogin_Click(object sender, System.EventArgs e)
{
string sUsername = TextUsername.Text.ToLower();
string sPassword = TextPassword.Text.ToLower();
if (FormsAuthentication.Authenticate(sUsername, sPassword))
{
Session["LoggedIn"] = "True";
FormsAuthentication.RedirectFromLoginPage(
sUsername,
CheckBoxRememberMe.Checked);
}
}

Here is the code in global.asa
Sub Session_OnStart
FrontPage_StartSession '==FrontPage Generated==
FrontPage_ConvertFromODBC '==FrontPage Generated==

if Session("LoggedIn") = "True" then
exit sub
end if
Session("LoggedIn") = "False"
dim sLink
sLink = "/members/Login.aspx" _
& "?ReturnUrl=" _
& Request.ServerVariables("SCRIPT_NAME")
Response.Redirect sLink
End Sub

If a user starts a session by going directly to a .asp page:
- Session_OnStart in global.asa will be called
- The LoggedIn session variable has not set
- The user will be redirected to the login page
- If the user logs in correctly:
- The LoggedIn session variable will be set to "True"
- The user will be redirected to the .asp page they requested

This seems to be working on my website.
Please exercise caution with this suggestion - this might not be the
best solution.
Your code will vary from this depending on the name and location of
your login page, and the type of forms authentication you use.

Good luck,
Michael Aaronson

--
MichaelAaronson
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: spike | last post by:
I tried to upload a .htaccess-file to the directory that i wanted to protect. This is what I wrote in it: ------------------------------------------------ <Limit GET> order deny,allow deny from...
1
by: Onur Bozkurt | last post by:
How can I deny access to a folder when authorization mode is none. I have xml files and I don't want then to be seen. When I restrict it from IIS, I can't read the files from codebehind.
3
by: david | last post by:
Hi, I have a asp.net site running on an MS Access database this is, for better or worse, stored under the webroot. How can I lockout the database directory to prevent anyone from...
4
by: Dan | last post by:
hi ng. i have a strange behaviour when i want to control who can access a web application by setting web.config like: <authorization> <allow users="DOMAIN\ACCOUNT,..." /> <deny users="*" /> ...
7
by: ABC | last post by:
How can I deny all users directly access image files from images folder?
2
by: psion | last post by:
Hello, I have not found a clear way of doing what I want and resort to posting my question. I have a php file that will link to pdf files from a directory called pdf (within the apache htdocs...
5
by: profdotnet | last post by:
Below is the code of web.config file: <configuration> <system.web> <authentication mode="Forms" /> <authorization> <allow users="Admin"/> <deny users="Jack,Mary" /> <deny users="?">...
0
by: ramakanaveen | last post by:
Hi , I have an applet like <Applet code="x.class" codebase="a.jar,b.jar" ...> The above a.jar and b.jar are in defaultwebapp folder of web application which is a public access folder, so...
1
by: Scottmat | last post by:
Hello, How do I control (allow / deny) access to files such as videos. It seems that can be used httphandler but I can not! Someone would have an idea or a concrete example of code ? Thank you
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.