Thursday, December 13, 2007

two login page in one application and Share the Themes and Master page

You have one application and after you realize that you need one more login page(Any reason) and also database table is different for checking username and Password. Then It is very hard to maintain the web.config file. As you can have only one Authentication per application.

Yes, I know I can add web.config file under directory but you can not add element.

My Directory stucture is as followed and my virtualdirectory name is "OnlineDemo"
OnlineDemo
- App_themes
onlinedemo
stylesheets.css
onlinedemo.skin
- Public
Registration.aspx
- Globals
Public.master
- Admin
default.aspx
- Web.config
- Login.aspx
In Web.config

<authentication mode="Forms">
<forms name="onlinedemo" defaultUrl="Admin/Default.aspx" />
</authentication>

Now, I have to add one more Directory called "Speaker" and if user wants to access it user need to login. Now question is how it is possible? as only one per application.

I created another virtualdirecoty under OnlineDemo called "Speakers". and there I put the web.config file.

<authentication mode="Forms">
<forms name="Sepakers" path="/" loginUrl="login.aspx"/>
</authentication>

So it will overwrite all the web.config setting from root Web.config. Here I soloved the problem of authentication.

Now, I have another problem occured how to share the Themes and Master page between two application. I do not want to copy and past under Speaker directory b'coz then I have to maintain 2 copies of Themes and Master Page.

Go to IISRight click on OnlineDemo --> Speaker --> New --> Virtual Directory give name App_Themes , Set the path to the App_themes finish.
Then right click on App_themes (Virtual Direcoty not folders). go to property --> Virtual Directory Tab Remove Application Name ("Remove" Button ) and Execute Permissions : Select "Script Only" from dropdown. follow same process for Globals.

And for Theme put <pages styleSheetTheme="onlinedemo"> in Web.Config
Now when you create new page under Speakers. give the MasterPageFile="~/Globals/Public.master"

No comments: