Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Secure some files of the Application
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Secure some files of the Application

 Post Reply Post Reply
Author
nima555ir View Drop Down
Newbie
Newbie
Avatar

Joined: 24 January 2003
Location: Iran
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote nima555ir Quote  Post ReplyReply Direct Link To This Post Topic: Secure some files of the Application
    Posted: 07 August 2003 at 7:51am
hi
i have an application that use form authentication.
but only there are some file that is secure and must user login to see them and other file is not secure and all user must be able to see them but when i use form authentication all file in application is protected and user must login to see them.
how can i do that?
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 07 August 2003 at 8:25am

Erm, your english is not to perfect, please explain what you exactly want.

If you want a form authentification script, the best thing is to write one yourself wich uses Acces databases and cookies. This is quite secure and gives alot of control on your users and user-states (banned, ipbanned, so on).

Writing one is quite a task (a secure one, not a If this Then that one), but once it is finished, it works as a dream. Include statements at each page or a couple of functions will do the job.

Gone..
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 07 August 2003 at 8:30am

The best security in .net is the built in one i think look for articles on using web.config in .net

Mart

Back to Top
nima555ir View Drop Down
Newbie
Newbie
Avatar

Joined: 24 January 2003
Location: Iran
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote nima555ir Quote  Post ReplyReply Direct Link To This Post Posted: 07 August 2003 at 10:31am

thanks for your reply but i havent got to my answer.

for example :

i have 5 file in my application:

admin.aspx,login.aspx,order.aspx,showitem.aspx,default.aspx

and i use form authentication to authenticate user.

but only the admin.aspx and order.aspx need authenticate user and for just this file user must authenticate and for other file all user can see them.

how can i do that?

thanx

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 07 August 2003 at 4:20pm

Alright, the best thing to do is to write a custom script. This is not very difficult, but the code depents on how many users there will be.

For example, if you only have 1 user, administrator in this case, you can simply use `If ... Then` statements. If you have more users and want to add and delete users in admin.aspx, you will need an Acces database (or SQL, but I preffer Acces (*.mdb)).

You still havent got an answer, so I'll trie and write a little code here, with a admin users, who can acces the admin.aspx, and regular users, who can acces the order.aspx.

Step 1:    Create a Acces database with two tables (tblAdmin, tblUsers)

Step 2:    Set a password for the Acces database

Step 3:    Upload the database in a directory called /Databases (or something like that)

Step 4:    Create two new files, order.aspx and admin.aspx

 - Now, you can choose between code-behind or in-line coded pages, I choose code-behind, but that's just because VS.net wants that. You can use this code in regular pages by using <script runat="server" lanugage="vb">

Step 5:   // Content of Order.aspx.vb (code behind)

Import System.Data
Import System.Data.OleDb


'The page designer code is left out, so this is not something to cut and paste

Sub Page_Load (ByVal e As System.Eventargs, (I forgot the rest..))

Dim myCookie as HttpCookie

'Check if the user is loggedin

myCookie = HttpContext.Current.Request.Cookies("something")

Try

     If myCookie.Item("loggedin").ToString() = "-10--10" Then
        'User is loggedin, show the page
        Response.WriteFile("order_content.aspx.txt")
     Else
        'User is not loggedin, show the login page
        Response.Redirect("Login.aspx")
     End If
Catch
     'Cookie doesn't exists (so he's not loggedin)
     Response.Redirect("Login.aspx")
End Try

End Sub

// Content Login.aspx (No code behind here! This is just a plain page)

<form action="Check_Login.aspx" method="POST">
<input type="textbox" name="txtUsername" value="Username">
<br>
<input type="password" name="txtPassword" value="...">
<br>
<br>
<input type="submit" value="Login to Order.aspx">
</form>

// Content Check_Login.aspx

<%@ runat="server" language="vb" %>
<%@ Import namespace="System.Data"%>
<%@ Import namespace="System.Data.OleDb"%>

<script runat="server" language="vb">

Sub Page_Load(...)

Dim myConn as OleDbConnection
Dim myDataAdapter as OleDbDataAdapter
Dim sqlStr as String, connStr as String

connStr = // Connection String here, look at
www.connectionstrings.com
myConn = New OleDbConnection(connStr)
myConn.Open

sqlStr = "SELECT * from tblUsers where username = '" & Request.Form("txtUsername") & "' And password = '" & Request.Form("txtPassword") & "'"
myDataAdapter = New OleDbDataAdapter(sqlStr, myConn)

If myDataAdapter.SelectCommand.ExecuteReader.Read.ToString() = False Then

    'Data isn't right
    Response.Redirect("Login.aspx")
    myConn.Close

Else

     'Data matches a user in the tblUsers
     Dim myCookie as HttpCookie
     myCookie = HttpContext.Response.Cookies("something")

     myCookie.Item("loggedin") = "-10--10"
     myCookie.Expires = Date() + 300
     Response.Redirect("Order.aspx")
     myConn.Close

End If

End Sub



The same thing is for the admin.aspx plus a couple of designer stuff. Now, I just wrote this in a few minutes, so don't trust it that much, it's just to give you an example of the way it works, if it works at all: the cookies are totaly different in ASP.Net, so some errors there I guess.

So don't reply if there is an error in it: I KNOW!

Gone..
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2003 at 3:03am

You can also use the web.config to authenticate, this is the most easy thing to do. Create a new directory (2 in the example, admin, order) and 2 web.config files.

Now, add the users wich will be allowed or denied in the web.config's and see what happens. I'm just a n00b in asp.net, but this looks quite good

Gone..
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.