Monday, May 23, 2011

Asp.net Web Config

Asp.net Config files some of the aspects and points to be remember

Purpose of the Config File in Asp.net:- The asp.net Config file is the mechanism which force the website to have common mechanism. We can fine tune our application with some configuration setting.

Configuration file is XML file.

The ASP.NET runtime processes configuration information hierarchically, proceeding from a
root common to all applications on the machine—machine.config—down to all the web.config files found in the various folders of the particular application.
Asp.Net Hierarchy :-

Machin.Config -> Web.Config -> Each folder
The first level of the configuration root is element

The section has two attributes: Path and allow Override. The Path attribute represents the virtual path to which the embedded settings apply.

The Section

Anonymous identification is a feature that assigns a predefined identity to users who connect
anonymously to an application. Anonymous identification has nothing to do with the anonymous
user you can set at the IIS level, nor does it affect the authentication mechanism of
ASP.NET. The feature is designed to work with the user profile API to simplify the way you
write code in scenarios where both authenticated and unauthenticated users can use the site.

The section will create Cookie or Coolie less token and attach it with our request.
AutoDetect Uses cookies if the browser has cookie support currently enabled. It uses the
cookieless mechanism otherwise.

UseCookie Always uses cookies, regardless of the browser capabilities.

UseDeviceProfile Uses cookies if the browser supports them, and uses the cookieless mechanism otherwise. When this option is used, no attempt is made to check
whether cookie support is really enabled for the requesting device. This is the
default option.

UseUri Never uses cookies, regardless of the browser capabilities.

The Section :-
The section enumerates the characteristics and capabilities of the supported
browsers, including mobile devices. The section is tightly coupled with the
HttpBrowserCapabilities class and MobileCapabilities, which allows the ASP.NET runtime to
gather technical information about the browser that is running on the client.


The Section
The section allows you to register application-specific HTTP handlers that take care of ad hoc
URLs invoked over given HTTP verbs. I’ll dissect the syntax and usage of the
section in the next chapter.

The Section
The section allows you to register application-specific HTTP modules that
take care of hooking up specific stages during the processing of an ASP.NET request. I’ll
dissect the syntax and usage of the section in the next chapter.

Wednesday, March 23, 2011

Find the biggest palindrome in the given string

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Palindrom
{
class Program
{
static void Main(string[] args)
{
string string1 = string.Empty;
string SubstringPali = string.Empty;
string Palindrom= string.Empty;
int Count=0;
int StartIndex;
int NextCount;
string GetPalindrom = string.Empty; ;


string1 = "asdadadasdiac aadaa erereraaggacaec";
StartIndex = 0;
foreach (char c in string1)
{
StartIndex++;
if (StartIndex <= string1.Length - 1)
{
if (string1.Substring(StartIndex).Contains(c))
{

SubstringPali = string1.Substring(StartIndex);
foreach (char cu in SubstringPali)
{
GetPalindrom += cu;
if (c == cu)
{
GetPalindrom = c + GetPalindrom;
if (CheckPalindrom(GetPalindrom))
{
NextCount = GetPalindrom.Length;
if (Count < NextCount) {
Count = NextCount;
}//if (Count < NextCount)
}// if (CheckPalindrom(GetPalindrom))
GetPalindrom = "";

break;
}//if (c = cu)
}// foreach (char cu in SubstringPali)

}// if (string1.Substring(StartIndex).Contains(c))
}//(StartIndex <= string1.Length - 1)

}// foreach (char c in string1)
Console.Write(" The max count of the palindrom is ={0}", Count);
Console.Read();
}

static bool CheckPalindrom(string Palindrom)
{
int Counter;
string RevPalindrom=string.Empty;
if (Palindrom.Length > 1)
{
for (Counter = Palindrom.Length - 1; Counter >= 0; Counter--)
{
RevPalindrom += Palindrom[Counter];
}
}
if (RevPalindrom == Palindrom)
{

return true;
}
else
{
return false;
}
}
}
}

Saturday, January 15, 2011

Custom MembershipProvider

Custom MembershipProvider

Following are the steps to configure your Windows predefined User Access mecanisum . following are the screen shots and steps how to configure SqlMembershipProvider with different data base instade of the Aspnet.mdb Sata Base

Step 0 Configure your data base with aspnet_regsql

Step 1 Create Class

This class will help to create our own member ship configuration with database.

The overridable method CreateUser will help to create new user in the data base

public class NGOSqlMembershipProvider : SqlMembershipProvider

{

public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)

{

if (username.ToLower() == password.ToLower())

{

status = MembershipCreateStatus.InvalidPassword;

return null;

}

else

{

return base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);

}

}

}

Setp 2 add machine key and algorithm which will use for generating the encryption in of our password

<machineKey validationKey="287C5D125D6B7E7223E1F719E3D58D17BB967703017E1BBE28618FAC6C4501E910C7E59800B5D4C2EDD5B0ED98874A3E952D60BAF260D9D374A74C76CB741803" decryptionKey="5C1D8BD9DF3E1B4E1D01132F234266616E0D5EF772FE80AB" validation="SHA1"/>

Step 3 Create connection string in web.config file this connection string we are going to pass to custom SqlProvider

<connectionStrings>

<add name="NgopediaConnection" connectionString="Data Source=SHREYAS-PC;Initial Catalog=DEMOTEST ;User ID=sa;Password=t#d98^55;"/>

<add name="NewConnectionstring" providerName="AspNetSqlProvider"

connectionStrings>

Step 4 Now the most important thing to update the configuration setting in the config file. Using this configuration setting login controls can access data

Note:- The type key word is very important in this we need to specify the class which is inherited by SqlMembershipProvider Class with fully qualified name should be there.

<add name="NgoNetSqlProvider"

connectionStringName="NgopediaConnection"

applicationName="/"

enablePasswordRetrieval="true"

enablePasswordReset="true"

requiresQuestionAndAnswer="true"

requiresUniqueEmail="true"

passwordFormat="Encrypted"

maxInvalidPasswordAttempts="5"

passwordAttemptWindow="10"

minRequiredPasswordLength="5"

minRequiredNonalphanumericCharacters="0"

type="NGOPEDIA.NGOSqlMembershipProvider"/>

and Your ready with your Custom MemberShip provider