473,382 Members | 1,814 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,382 software developers and data experts.

Form-based Authentication

I am trying to use Forms-based authentication. I followed MS Support Q301240
article. I want to control access to a folder (swhouse) and its contents.
Below is the sample of actual web.config.

<configuration>
<location path="swhouse" >
<system.web>
<authentication mode="Forms">
<forms name=".partnerslogin"
loginUrl="/CompanyWebsite/partnerlogin.aspx" protection="All"
timeout="30" path="\"></forms>
</authentication>
<authorization>
<allow users = "asim" />
<deny users="?"/>
</authorization>
</system.web>
</location>
<location>
<system.web>
<compilation defaultLanguage="c#" debug="false" />
<authentication mode="None"/>
<trace enabled="false" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false" timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</location>
</configuration>

Next I created a webform and named it partnerlogin.aspx. This page contains
2 textboxes, for user name and password, and a submit button, when the user
clicks the submit button the following code is executed (at this time it does
not include any kind of user name validation as I wanted to get this working
first)

private void btnLogin_Click(object sender, System.EventArgs e)
{
try
{
// authenticate user...
// after authentication send to appropriate page or presentation
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
"asim",
System.DateTime.Now,
System.DateTime.Now.AddMinutes(30),
true,
"",
FormsAuthentication.FormsCookiePath);

// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);

// Create the cookie.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
encTicket));

// Redirect back to original URL.
string strRedirect =Request["ReturnUrl"];
if (strRedirect==null)
strRedirect = "partnerlogin.aspx";
Response.Redirect(strRedirect, true);
Response.Redirect(FormsAuthentication.GetRedirectU rl("asim", false));
}
catch (SystemException SysExp)
{
lblErrorMessage.Visible = true;
lblErrorMessage.Text = SysExp.Message;
}

}
Now the problem I am seeing is that the page I am trying to access never
gets rendered. But if I remove <deny users="?"/> from web.config the page
gets rendered. So it seems that I am doing something wrong but I can't
figure what. Any help will be greatly appreciated.
Thanks

Asim

Nov 19 '05 #1
2 1060
Asim what do u really want to do?
Do u want to allow only "ASIM" as a user or allow authnticated Users?
"Asim" wrote:
I am trying to use Forms-based authentication. I followed MS Support Q301240
article. I want to control access to a folder (swhouse) and its contents.
Below is the sample of actual web.config.

<configuration>
<location path="swhouse" >
<system.web>
<authentication mode="Forms">
<forms name=".partnerslogin"
loginUrl="/CompanyWebsite/partnerlogin.aspx" protection="All"
timeout="30" path="\"></forms>
</authentication>
<authorization>
<allow users = "asim" />
<deny users="?"/>
</authorization>
</system.web>
</location>
<location>
<system.web>
<compilation defaultLanguage="c#" debug="false" />
<authentication mode="None"/>
<trace enabled="false" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false" timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</location>
</configuration>

Next I created a webform and named it partnerlogin.aspx. This page contains
2 textboxes, for user name and password, and a submit button, when the user
clicks the submit button the following code is executed (at this time it does
not include any kind of user name validation as I wanted to get this working
first)

private void btnLogin_Click(object sender, System.EventArgs e)
{
try
{
// authenticate user...
// after authentication send to appropriate page or presentation
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
"asim",
System.DateTime.Now,
System.DateTime.Now.AddMinutes(30),
true,
"",
FormsAuthentication.FormsCookiePath);

// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);

// Create the cookie.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
encTicket));

// Redirect back to original URL.
string strRedirect =Request["ReturnUrl"];
if (strRedirect==null)
strRedirect = "partnerlogin.aspx";
Response.Redirect(strRedirect, true);
Response.Redirect(FormsAuthentication.GetRedirectU rl("asim", false));
}
catch (SystemException SysExp)
{
lblErrorMessage.Visible = true;
lblErrorMessage.Text = SysExp.Message;
}

}
Now the problem I am seeing is that the page I am trying to access never
gets rendered. But if I remove <deny users="?"/> from web.config the page
gets rendered. So it seems that I am doing something wrong but I can't
figure what. Any help will be greatly appreciated.
Thanks

Asim

Nov 19 '05 #2

Patrick

We have some presentations which we want to put on the webserver, but not
all the authenticated users should have access to it. So what I am trying to
do is create separate directories and then give certain users access to those
directories and their contents. Basically user 'A' should have access to
presentation 'A' in directory 'A' but he should not have access to
presentation 'B' in directory 'B'. I want to put the users in the database
and authenticate them once they enter their user name and password. That's
the easy part.

So in the sample code which I added to my post, I want only user "asim" to
have access to the directory "swhouse" and it's contents. But so far what
code is doing is bringing me back to the login page.

Thanks

Asim

Nov 19 '05 #3

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

Similar topics

3
by: John | last post by:
Dear all, It been more than 3 days I am trying to debug this program, I interpret it using activePerl and it is giving (perl -wc code_process.pl) no error syntax but when I put it online, change...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
4
by: Targa | last post by:
Trying to total some price fields in a form but doesnt work when all the referenced form fields dont exisit. This is for an invoice - pulled prom a database and the form doesnt always contain the...
19
by: Raposa Velha | last post by:
Hello to all! Does any of you want to comment the approach I implement for instantiating a form? A description and an example follow. Cheers, RV jmclopesAThotmail.com replace the AT with the...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.