C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to Authenticating Specific File And Floder


Posted Date: 16 Oct 2008      Total Responses: 3

Posted By: sandip chavan       Member Level: Silver     Points: 1


I Want to Create Site That Any Public Access but Having Credential
For Each Page How Can I Give IT.Any User he/her goes from Login And Pass Word
If he enter URL of Any Page then he Redirect to Login Page.Code ...
Ex..




Responses

Author: Meetu Choudhary    16 Oct 2008Member Level: GoldRating:     Points: 1
Please use form authentication and there you can provide the access to different users and for different folders or files using roles...

==
Thanks and Regards
Meetu Choudhary


Author: gomathinayagam    16 Oct 2008Member Level: GoldRating:     Points: -8
add form authentication in web config.
that will help to do these all things.

in web config :

<authentication mode="Forms">
<forms loginUrl="Login.aspx" name="sqlAuthCookie" defaultUrl="Home.aspx" timeout="60" path="/">
</forms>
</authentication>

<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>

in login page login button click event
after password verified:

FormsAuthentication.SetAuthCookie(this.txtUserName.Text.Trim(), false);
FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket(1, this.txtUserName.Text.Trim(), DateTime.Now, DateTime.Now.AddDays(2), false, "user");
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket1));
Response.Cookies.Add(cookie1);
string returnUrl;
if (Request.QueryString["ReturnUrl"] == null)
{
returnUrl = "Default.aspx";
}
else
{
returnUrl = Request.QueryString["ReturnUrl"];
}
Response.Redirect(returnUrl);




Author: Nagarajan    16 Oct 2008Member Level: GoldRating:     Points: -20
TRy using forms authentication

Forms Authetication is a cookie based authentication system where the username and passport is stored in a database

Define your web.config as below

configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="login.aspx" protection="All" timeout="30">
</forms>
</authentication>
</system.web>

So, when you the user is not authenticated and if he is trying to access as page, then the page gets redirected to login page, defined in web.config.


You can check authentication in login page and redirect from the
it as below
if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(username.Text, true);
}
else
{
// Do Something for invalid login
}



Hope below url would help you setting up forms authentication with SQL


How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
http://msdn.microsoft.com/en-us/library/ms998317.aspx

Also to get a good knowledge on Forms Authentication try the below url too
Explained: Forms Authentication in ASP.NET 2.0
http://msdn.microsoft.com/en-us/library/aa480476.aspx


Hope this helps
Happy Coder


Post Reply
You must Sign In to post a response.
Next : plz answer this
Previous : CSS for any browser
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use