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"

How to Share Session State Between Classic ASP and ASP.NET

How to Share Session State Between Classic ASP and ASP.NET

http://msdn2.microsoft.com/en-us/library/aa479313.aspx

How to upload a .SQL file to a Hoster and Execute it to Deploy a SQL Database

Tip/Trick: How to upload a .SQL file to a Hoster and Execute it to Deploy a SQL Database

http://weblogs.asp.net/scottgu/archive/2007/01/11/tip-trick-how-to-upload-a-sql-file-to-a-hoster-and-execute-it-to-deploy-a-sql-database.aspx

Creating Packaged ASP.NET Setup Programs with VS 2005

Creating Packaged ASP.NET Setup Programs with VS 2005

http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx

ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas By ScottGu

http://weblogs.asp.net/scottgu/pages/ASP.NET-2.0-Tips_2C00_-Tricks_2C00_-Recipes-and-Gotchas.aspx

Dynamically / Programatically get IIS Version

you can get the IIS Version programically by using following way. If you are using Windows 2003 or Windows Vista then you can get by using

DirectoryEntry dirRoot = new DirectoryEntry(IISRoot);
DirectoryEntry child = dirRoot.Children.Find("Info", "IIsWebInfo");
foreach (PropertyValueCollection c in child.Properties)
{
if (string.Compare(c.PropertyName, "MajorIIsVersionNumber", StringComparison.CurrentCultureIgnoreCase) == 0)
{
return Convert.ToInt16(c.Value, CultureInfo.InvariantCulture);
}
}

But if you are using windows XP then It is difficult to get it as it store in a binary. So I tried following way to get the IIS Version and in my case it works fine.

try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + @"\inetsrv\inetinfo.exe");
Console.WriteLine("Version:" + fvi.FileVersion +"\nMajor Part: " + fvi.FileMajorPart + "." + fvi.FileMinorPart);
}
catch (FileNotFoundException ex)
{
throw ex;
}

How to use Office .NET Interop Assemblies

http://msdn2.microsoft.com/en-us/library/aa159923(office.11).aspx