How to create Login and redirect to any aspx page?

Discussion in 'ASP.NET / ASP.NET Core' started by Bruce, Jun 23, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Bruce

    Bruce DiscountASP.NET Staff

    check out this article

    http://www.asp101.com/articles/cynthia/authentication/default.asp

    It describe using form based authentication with asp.net, you'll need to add some login to query your database in the login.aspx page.


    quote:Originally posted by laks

    I want to create a login page with access database connection.
    All I want to do is, In asp.net page I want to add username,
    password textbox and also submit button. Once I click the submit button I want to see whether the username and password are existing in the access database(Table name-UserTable) or not. If it exists in the databse then redirect to some other asp.net page. If it is not then stay in the same page with error message.

    I am new in the .Net , It may be a silly question.

    Since I am not familier with syntax and C# also.

    I want to use C# and asp.net....

    Please give me some ideas and solution for this issue.

    Pls help me out!

    Thanks in Advance,
    laks
    </blockquote id="quote"></font id="quote">
     
  2. I want to create a login page with access database connection.
    All I want to do is, In asp.net page I want to add username,
    password textbox and also submit button. Once I click the submit button I want to see whether the username and password are existing in the access database(Table name-UserTable) or not. If it exists in the databse then redirect to some other asp.net page. If it is not then stay in the same page with error message.

    I am new in the .Net , It may be a silly question.

    Since I am not familier with syntax and C# also.

    I want to use C# and asp.net....

    Please give me some ideas and solution for this issue.

    Pls help me out!

    Thanks in Advance,
    laks
     
  3. This week I created a secure login page so I can do some database administration online by passing SQL statements. I didn't want anyone else to have access except me. I did what you describe but in vb.net and my password is hardwired in the code right now. I just created another directory and set the permissions in the web.config of the new directory to deny all users as follows:


    <configuration>
    <system.web>
    <authorization>
    <deny users="?" /> <!-- deny all users -->
    </authorization>
    </system.web>
    </configuration>

    The web.config in the root directory should have something like this


    <authentication mode="Forms" >
    <forms name ="SQLadmin" loginUrl = "logon.aspx" protection="All" timeout="60" />
    </authentication>

    <authorization>
    <allow users="*" /> <!-- Allow all users -->
    </authorization>

    When someone tries to access the page in the directory where you have denied permissions you are redirected to a logon.aspx page that you have to create that has something like this:

    Private Sub bntLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntLogin.Click
    If Page.IsValid Then
    If txtUN.Text = "your username" And txtPW.Text = "yourpassword" Then
    'redirects to the originally requested page
    FormsAuthentication.RedirectFromLoginPage(txtUN.Text, True)
    Else
    lblMessage.Visible = True
    lblMessage.Text = "Invalid Login. Try Again"
    End If
    End If
    End Sub

    In the place of my hardwired username and password, you simple put in code to lookup it up in your database.

    You click a button and you are authenicated by your code and you are then redirected to the origally requested source by
    FormsAuthentication.RedirectFromLoginPage. If the second parameter is set to true as shown above a persistent cookie is set so you will not have to login again from the same brower. If set to false you have to login with each new browser session.

    I found the key to making this work in getting parameters set correctly in root directory web.config and the protected directory web.config files.

    It is pretty simple and I hope the wrapping does not make this unreadable.

    Hope this helps. It seems to work great.

    Brian


    quote:Originally posted by laks

    I want to create a login page with access database connection.
    All I want to do is, In asp.net page I want to add username,
    password textbox and also submit button. Once I click the submit button I want to see whether the username and password are existing in the access database(Table name-UserTable) or not. If it exists in the databse then redirect to some other asp.net page. If it is not then stay in the same page with error message.

    I am new in the .Net , It may be a silly question.

    Since I am not familier with syntax and C# also.

    I want to use C# and asp.net....

    Please give me some ideas and solution for this issue.

    Pls help me out!

    Thanks in Advance,
    laks
    </blockquote id="quote"></font id="quote">
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    You can also put the connection string in web.config file. Web.config file is not downloable from the web.

    quote:Originally posted by bdwest

    This week I created a secure login page so I can do some database administration online by passing SQL statements. I didn't want anyone else to have access except me. I did what you describe but in vb.net and my password is hardwired in the code right now. I just created another directory and set the permissions in the web.config of the new directory to deny all users as follows:


    <configuration>
    <system.web>
    <authorization>
    <deny users="?" /> <!-- deny all users -->
    </authorization>
    </system.web>
    </configuration>

    The web.config in the root directory should have something like this


    <authentication mode="Forms" >
    <forms name ="SQLadmin" loginUrl = "logon.aspx" protection="All" timeout="60" />
    </authentication>

    <authorization>
    <allow users="*" /> <!-- Allow all users -->
    </authorization>

    When someone tries to access the page in the directory where you have denied permissions you are redirected to a logon.aspx page that you have to create that has something like this:

    Private Sub bntLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntLogin.Click
    If Page.IsValid Then
    If txtUN.Text = "your username" And txtPW.Text = "yourpassword" Then
    'redirects to the originally requested page
    FormsAuthentication.RedirectFromLoginPage(txtUN.Text, True)
    Else
    lblMessage.Visible = True
    lblMessage.Text = "Invalid Login. Try Again"
    End If
    End If
    End Sub

    In the place of my hardwired username and password, you simple put in code to lookup it up in your database.

    You click a button and you are authenicated by your code and you are then redirected to the origally requested source by
    FormsAuthentication.RedirectFromLoginPage. If the second parameter is set to true as shown above a persistent cookie is set so you will not have to login again from the same brower. If set to false you have to login with each new browser session.

    I found the key to making this work in getting parameters set correctly in root directory web.config and the protected directory web.config files.

    It is pretty simple and I hope the wrapping does not make this unreadable.

    Hope this helps. It seems to work great.

    Brian


    quote:Originally posted by laks

    I want to create a login page with access database connection.
    All I want to do is, In asp.net page I want to add username,
    password textbox and also submit button. Once I click the submit button I want to see whether the username and password are existing in the access database(Table name-UserTable) or not. If it exists in the databse then redirect to some other asp.net page. If it is not then stay in the same page with error message.

    I am new in the .Net , It may be a silly question.

    Since I am not familier with syntax and C# also.

    I want to use C# and asp.net....

    Please give me some ideas and solution for this issue.

    Pls help me out!

    Thanks in Advance,
    laks
    </blockquote id="quote"></font id="quote">
    </blockquote id="quote"></font id="quote">
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page