Multiple Web.config files

Discussion in '.NET' started by krish.mtm143, Nov 18, 2009.

  1. krish.mtm143

    krish.mtm143

    Joined:
    Nov 18, 2009
    Messages:
    1
    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: Nov 18, 2009
    krish.mtm143, Nov 18, 2009
    #1
    1. Advertising

  2. krish.mtm143

    ExpertPractice

    Joined:
    Jan 14, 2010
    Messages:
    6
    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: Feb 5, 2010
    ExpertPractice, Jan 15, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benny Ng
    Replies:
    9
    Views:
    10,003
    Benny Ng
    Oct 13, 2005
  2. googlinggoogler@hotmail.com
    Replies:
    4
    Views:
    962
    M.E.Farmer
    Feb 13, 2005
  3. CSharpner
    Replies:
    0
    Views:
    1,061
    CSharpner
    Apr 9, 2007
  4. Ollie Riches
    Replies:
    1
    Views:
    1,653
    Gregory A. Beamer
    Dec 4, 2008
  5. Nick Johnson

    Windows Application App.config Files vs. web.config

    Nick Johnson, Mar 12, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    674
    Nick Johnson
    Mar 12, 2007
Loading...

Share This Page