Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Multiple Web.config files

Reply
Thread Tools

Multiple Web.config files

 
 
krish.mtm143 krish.mtm143 is offline
Junior Member
Join Date: Nov 2009
Posts: 1
 
      11-18-2009
hi,

Q.how to maintain different sessionid for different sub folders in Asp.net webappli.,

rootfolder(myweb)
--folder1(Admin)
Login.aspx
Logout.aspx
pageAdmin1.aspx
pageAdmin2.aspx
pageAdmin3.aspx
adminweb.config(forms authentication)
--folder2(Userpages)
Login.aspx
Logout.aspx
page1.aspx
page2.aspx
page3.aspx
userweb.config(forms authentication)

i want to maintain two different sessionids for these folders. i mean if i logged from admin module it does't effect the userpages. viceversa..
pls..help me
 

Last edited by krish.mtm143; 11-18-2009 at 06:36 AM..
Reply With Quote
 
 
 
 
ExpertPractice ExpertPractice is offline
Junior Member
Join Date: Jan 2010
Posts: 7
 
      01-15-2010
What i understand is ..u are actually looking for authorizing different users for different parts of your application. Like you want admin to access both User Pages and Admin pages but you want User to Access only the User Pages.
To Achieve that you dont actully need multiple web.config files.

Follow these steps

Add this to you Login form set it according to you authentication system.


Role= Get it from Db whether its an Admin or a User after checking UserName and Password.
/////Create Authentication Ticket Manually///////

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddMinutes(20), true, Role);
string HashedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashedTicket);
cookie.HttpOnly = true;
if (ticket.IsPersistent)
{
cookie.Expires = ticket.Expiration;
}
Response.Cookies.Add(cookie);

Add This to Global.asax

void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (Context.User != null && Context.User.Identity.AuthenticationType=="Forms")
{
System.Security.Principal.IIdentity ID = Context.User.Identity;
FormsIdentity FrmID = (FormsIdentity)ID;
FormsAuthenticationTicket ticket = FrmID.Ticket;
string[] Roles = ticket.UserData.Split(',');
Context.User = new System.Security.Principal.GenericPrincipal(ID, Roles);
}
}

In Global.asax we are setting Role of the User To the current Context

Finally Define Roles in the web.config

<authentication mode="Forms">
<forms defaultUrl="index.aspx" loginUrl="index.aspx" name="MyFormCookie" protection="All" slidingExpiration="true" timeout="20">
</forms>
</authentication>
<authorization>
<allow users="*" />
</authorization>


<location path="Admin">
<system.web>
<authorization>
<allow roles="admin" />
<deny users="*" />
</authorization>
</system.web>
</location>

<location path="UserPages">
<system.web>
<authorization>
<allow roles="admin,User" />
<deny users="*" />
</authorization>
</system.web>
</location>

define these settings at their appropriate locations in web.config



Hope this will help




@li
 

Last edited by ExpertPractice; 02-05-2010 at 07:24 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
#define and #undef influence over all the files (Multiple C Files) karthikbalaguru C Programming 3 11-27-2008 01:45 PM
multiple rake build files? large rake files thufir Ruby 3 04-12-2008 07:28 AM
how i can extract text from the PDF files,power point files,Ms word files? crazyprakash Java 4 10-30-2005 10:17 AM
Text files read multiple files into single file, and then recreate the multiple files googlinggoogler@hotmail.com Python 4 02-13-2005 05:44 PM
Beginner Help: Joining Multiple classes in multiple files? JHenstay C++ 3 01-11-2004 02:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57