Difference between Session state and Application state
Session state:
- The session object is used to maintain the session of each user. A user gets a session id when he enters in to an application. This Id will delete when he leave from that application. If he enters again he will get a different session Id.
- Session allows information to be stored in one page and access in another page and support any type of object.
Application state:
- But the application object, the Id is maintained for whole application.
- Application state allows storing global objects that can be accessed by any client.
...S.VinothkumaR.
Difference between View State and Session State
Session state and view state are used to keep on certain data.
View State:
- View state is maintained in page level only.
- View state of one page is not visible in another page.
- View state information stored in client only.
- View state persist the values of particular page in the client (browser) when post back operation done.
- View state used to persist page-instance-specific data.
Session State:
- Session state is maintained in session level.
- Session state value is available in all pages within a user session.
- Session state information stored in server.
- Session state persist the data of particular user in the server. This data available till user close the browser or session time completes.
- Session state used to persist the user-specific data on the server side.
...S.VinothkumaR.
How to send Authenticated Emails?
private void SendMail()
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("vinothnat@hotmail.com", "Vinothkumar");
mail.To.Add(new MailAddress("vinoth_nat@hotmail.com", "S.Vinothkumar"));
//To property is a generic collection. So we can add as many recipients as we like
mail.Subject = "TestMail";
mail.Body = "I am testing the mail with credentials.";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("localhost");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential credential = new NetworkCredential("username", "password");
smtp.UseDefaultCredentials = false;
smtp.Credentials = credential;
smtp.Send(mail);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
...S.VinothkumaR.
Sql Server Function to get number of working days in given days.
CREATE FUNCTION dbo.GetWorkingDays
(
@startDate SMALLDATETIME,
@endDate SMALLDATETIME
)
RETURNS INT
AS
BEGIN
DECLARE @WDays INT;
SET @WDays = DATEDIFF(DAY, @startDate, @endDate)+1;
RETURN
(
SELECT @WDays / 7 * 5 + @WDays % 7 -
(
SELECT COUNT(*) FROM
(
SELECT 1 AS d
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
UNION ALL SELECT
) weekdays
WHERE d <= @WDays % 7
AND DATENAME(WEEKDAY, @endDate - d + 1)
IN
(
'Saturday',
'Sunday'
)
)
);
END
GO
PRINT dbo.getWorkingDays('20080601', '20080630')
...S.VinothkumaR.
SQL Server Function to get Number Of Days in a month.
CREATE FUNCTION dbo.GetNumberOfDays
(
@inMonth DATETIME
)
RETURNS INT
AS
BEGIN
Declare @Days int
Set @Days=0
set @Days=CASE WHEN MONTH(@inMonth) IN (1,3,5,7,8,10,12) THEN 31
WHEN MONTH(@inMonth) IN (4,6,9,11) THEN 30
ELSE CASE WHEN (YEAR(@inMonth) % 4 = 0 AND YEAR(@inMonth) % 100!=0) OR (YEAR(@inMonth) % 400=0) THEN 29
ELSE 28 END
END
Return
(
select @Days
);
END
PRINT dbo.GetNumberOfDays(getDate())
...S.VinothkumaR.
Easy way to find browsers in JavaScript
Hi all,
Here I have written a JavaScript function to get the browser.
function myBrowser()
{
var browser=navigator.userAgent.toLowerCase();
if (browser.indexOf("msie") != -1)
return 'Internet Explorer';
if (browser.indexOf("firefox") != -1)
return 'Firefox';
if (browser.indexOf("opera") != -1)
return 'Opera';
if (browser.indexOf("safari") != -1)
return 'Safari';
if (browser.indexOf("netscape") != -1)
return 'Netscape';
if (browser.indexOf("mozilla/5.0") != -1)
return 'Mozilla';
if (browser.indexOf("staroffice") != -1)
return 'Star Office';
if (browser.indexOf("webtv") != -1)
return 'WebTV';
if (browser.indexOf("beonex") != -1)
return 'Beonex';
if (browser.indexOf("chimera") != -1)
return 'Chimera';
if (browser.indexOf("netpositive") != -1)
return 'NetPositive';
if (browser.indexOf("phoenix") != -1)
return 'Phoenix';
if (browser.indexOf("skipstone") != -1)
return 'SkipStone';
}
...S.VinothkumaR.
Alternate to location.href
Actually the location.href functionality is some times not working in firefox . So we can use the following way is the alternative for "location.href."
top.window.opener.location.href
...S.VinothkumaR.