Saturday, May 30, 2015
Tuesday, May 26, 2015
Production Incident 10: Default Proxy Or Proxy Or CORS When Remote Name Cannot be resolved
Issue: Remote Name cannot be resolved.
Scenario: When we call third party or cross domain api within our web api.
Resolution :
"usesystemdefault="True" />Scenario: When we call third party or cross domain api within our web api.
Resolution :
- Enable CORs at third party api Or
- Try to include default proxy
- Or specific proxy at your client web APi
<system.net>
</system.net>
</system.net>
Or
</system.net>
Or
Enable Cors
Error Slab:
Friday, May 1, 2015
Production Support Incident 6: Bad Architecture Design Database server Box having IIS webserver
Architecture Scenario:
A shared database SQL Server physical box or VM contains shared databases which is connected to different web servers hosted with different website. Lets assume within that database box we have IIS configured with WCF hosted service. The initial objective would be the wcf service which is present within database server must be using database table for storing service data. This is bad design.
What is the problem?
Now when we allocate RAM to SQL server box , sql server consumes all the RAM and keep very little RAM for OS activity. Now lets assume we have IIS configured with wcf service with database server and there is very little RAM available for IIS and OS as SQL server consumes most of the RAM memory . In such case there is going to be memory overflow or Network IO wait conditions for website request that are sending requests to this wcf service hosted in IIS that resides within this database server.
Workaround: You have to explicitly allocate RAM for sql server and for IIS to process the requests. The flipside is your sql server may started getting load and RAM consumption may shoot up to peek which may results in Suspended transactions and process requests with latency.
This is design flaw at infrastructure Level hence it is always important to make assessment and revisit architecture.
A shared database SQL Server physical box or VM contains shared databases which is connected to different web servers hosted with different website. Lets assume within that database box we have IIS configured with WCF hosted service. The initial objective would be the wcf service which is present within database server must be using database table for storing service data. This is bad design.
What is the problem?
Now when we allocate RAM to SQL server box , sql server consumes all the RAM and keep very little RAM for OS activity. Now lets assume we have IIS configured with wcf service with database server and there is very little RAM available for IIS and OS as SQL server consumes most of the RAM memory . In such case there is going to be memory overflow or Network IO wait conditions for website request that are sending requests to this wcf service hosted in IIS that resides within this database server.
Workaround: You have to explicitly allocate RAM for sql server and for IIS to process the requests. The flipside is your sql server may started getting load and RAM consumption may shoot up to peek which may results in Suspended transactions and process requests with latency.
This is design flaw at infrastructure Level hence it is always important to make assessment and revisit architecture.
Production Support Incident 5: Enable default proxy to access internet content or any outside DMZ API
Sometimes production webserver servers are not allowed to access outside internet web to prevent any vulnerable attack within the server.
Sometime there may be requirement to call web api which is hosted in cloud and your private intranet web server requires to call those api which is hosted externally in such case we may use internal proxy within the network to make a call across firewall.
To enable the proxy setting I
have added following piece of code in config file
Even after allowing access through proxy the server certificates are not configured properly which may results in further execution. Ensure certificates are installed in browser to make handshake to the api.
Check certificates in server
https://technet.microsoft.com/en-au/library/cc754431.aspx
Production Support Incident 3: Disable SSlv3 Poddle Attack on Azure web role and worker Role
Poodle attack - SSLV3 Enabled
Tool to ---Test your website server is poodle free..poodle test?
https://www.ssllabs.com/ssltest/
Courtesy: http://en.wikipedia.org/wiki/POODLE
The POODLE attack (which stands for "Padding Oracle On Downgraded Legacy Encryption") is a man-in-the-middle exploit which takes advantage of Internet and security software clients'
Website and server should be poodle free, its vulnerable if we have SSLV3 policy protocol is enabled. One can disabled SSLV3 through regedit whereas in cloud we have to disable using startup script in Service definitions.
1. Add .cmd batch file in startup script of Role profile folder.
2. Give path of start up script in servicedefination configuration under task tag.
3. Keep the powershell file in root of website or webrole.
4. Ensure ps1 file is copy to content always. Right click on powershell file in solution VS and check property to enable this options.
Importantly!
Even after deployment your SSL scan test lab shows you C grade check for webseal or WAF (Web application firewall). In such case you may have to disable ssl in server that is acting as firewall. Check with your infrastructure team.
****Check any WAF environment. Web application Firewall behind which your azure web role may resides.
http://www.ideliverable.com/blog/making-iis-configuration-changes-in-a-web-role-startup-task
http://blogs.msdn.com/b/jimoneil/archive/2011/02/07/azure-startup-tasks-and-powershell-lessons-learned.aspx
http://www.dotnettwitter.com/2011/11/executing-powershell-script-with.html
http://stackoverflow.com/questions/15350936/running-powershell-from-azure-startup-task
http://stackoverflow.com/questions/28888768/adding-startup-script-to-azure-web-role-copy-to-output-directory-missing
http://www.troyhunt.com/2014/10/disabling-ssl-3-in-azure-websites-and.html
http://blogs.msdn.com/b/kaushal/archive/2014/10/22/poodle-vulnerability-padding-oracle-on-downgraded-legacy-encryption.aspx
Web servers
Apache
Nginx
Lighttpd
Tool to ---Test your website server is poodle free..poodle test?
https://www.ssllabs.com/ssltest/
Courtesy: http://en.wikipedia.org/wiki/POODLE
The POODLE attack (which stands for "Padding Oracle On Downgraded Legacy Encryption") is a man-in-the-middle exploit which takes advantage of Internet and security software clients'
Website and server should be poodle free, its vulnerable if we have SSLV3 policy protocol is enabled. One can disabled SSLV3 through regedit whereas in cloud we have to disable using startup script in Service definitions.
1. Add .cmd batch file in startup script of Role profile folder.
2. Give path of start up script in servicedefination configuration under task tag.
3. Keep the powershell file in root of website or webrole.
4. Ensure ps1 file is copy to content always. Right click on powershell file in solution VS and check property to enable this options.
Importantly!
Even after deployment your SSL scan test lab shows you C grade check for webseal or WAF (Web application firewall). In such case you may have to disable ssl in server that is acting as firewall. Check with your infrastructure team.
****Check any WAF environment. Web application Firewall behind which your azure web role may resides.
http://www.ideliverable.com/blog/making-iis-configuration-changes-in-a-web-role-startup-task
http://blogs.msdn.com/b/jimoneil/archive/2011/02/07/azure-startup-tasks-and-powershell-lessons-learned.aspx
http://www.dotnettwitter.com/2011/11/executing-powershell-script-with.html
http://stackoverflow.com/questions/15350936/running-powershell-from-azure-startup-task
http://stackoverflow.com/questions/28888768/adding-startup-script-to-azure-web-role-copy-to-output-directory-missing
http://www.troyhunt.com/2014/10/disabling-ssl-3-in-azure-websites-and.html
http://blogs.msdn.com/b/kaushal/archive/2014/10/22/poodle-vulnerability-padding-oracle-on-downgraded-legacy-encryption.aspx
Please engage the team who maintains these Linux box and follow document
below to disable SSL3.
Web servers
Apache
Put the following line in your configuration file, or
replace any existing line starting with
SSLProtocol:SSLProtocol All -SSLv2 -SSLv3
Then run:
sudo apache2ctl configtest
&& sudo service apache2 restart.
Don't forget to test your
website.
Nginx
Put the following line in your configuration file, or
replace any existing line starting with
ssl_protocols:ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
Then restart the server (in Ubuntu:
sudo service nginx restart).
Don't forget to test your
website.
Lighttpd
Lighttpd releases before 1.4.28 allow you to disable
SSLv2 only.
If you are running at least 1.4.29, put the following
lines in your configuration file:
ssl.use-sslv2 = "disable"
ssl.use-sslv3 = "disable"
Then restart the server (in Ubuntu:
sudo service lighttpd restart).
Don't forget to test your
website.
Wednesday, April 8, 2015
Production support Incident 2 : Never Rely on LINQ Object IEumerable
If you are supporting application that have nhibernate, entity framework without stored procedures setup, there will speed breaker ahead in your journey. It may work fine for given capacity and user base but sometimes may give you a surprise.
Something below in your query would ring a alarm bell.
return logEntries.ToList().Take(10);
This particular query will bring resultsets from database to webserver and then fetch 10 records for you. Just imagine for some reason and data combination you got thousands of records from database and then it manipulates something web server with these sets of resultset, surely your web server CPU will spikes for sure. There will be intermittent downtimes due to concurrent users. If there is caching profile then there could be possible race condition to create them. There are possible potential occurrence of hung and suspended transactions in sql server and so on.
You even think of brute force method to KILL SPID...and you save sometime to rescue yourself. If you're a support guy then it is good you atleast know what LINQ object query does in the background. With just little knowledge on the surface won't help. You may take short cut to fix this by mounting or increasing server configuration however this short term solution and this may blow out of proportion in another next month due to increase in users and process.
Stop gap arrangement :- to maintain P1 at bay. until you fix the main solution.
Something below in your query would ring a alarm bell.
return logEntries.ToList().Take(10);
This particular query will bring resultsets from database to webserver and then fetch 10 records for you. Just imagine for some reason and data combination you got thousands of records from database and then it manipulates something web server with these sets of resultset, surely your web server CPU will spikes for sure. There will be intermittent downtimes due to concurrent users. If there is caching profile then there could be possible race condition to create them. There are possible potential occurrence of hung and suspended transactions in sql server and so on.
You even think of brute force method to KILL SPID...and you save sometime to rescue yourself. If you're a support guy then it is good you atleast know what LINQ object query does in the background. With just little knowledge on the surface won't help. You may take short cut to fix this by mounting or increasing server configuration however this short term solution and this may blow out of proportion in another next month due to increase in users and process.
Stop gap arrangement :- to maintain P1 at bay. until you fix the main solution.
SET NOCOUNT ON
PRINT 'Checking for
long running processes'
DECLARE @TRANSACTION_STATUS as varchar(40)
Declare @TimeElapsed as
decimal
Set @TimeElapsed =0.001
set @TRANSACTION_STATUS ='SUSPENDED'
CREATE TABLE
##temp (
[SPID] [varchar] (13),
[Status] [varchar] (120),
[Login] [varchar] (120),
[HostName] [varchar] (120),
[BlkBy] [varchar] (13),
[DBName] [varchar] (120),
[Command] [varchar] (130),
[CPUTime] [varchar] (120),
[DiskIO] [varchar] (120),
[LastBatch] [varchar] (130),
[ProgramName] [varchar] (140),
[SPID2] [varchar] (13),
[REQUESTID] [varchar] (13)
)
--Keep Only Recipe Related Suspended Logs /Details to
process further
INSERT INTO
##temp
(SPID,[Status],[Login],HostName,BlkBy,DBName,Command,CPUTime,DiskIO,LastBatch,ProgramName,SPID2, REQUESTID)
EXECUTE sp_who2
DELETE from ##temp where not [login] = 'xyz'
or not dbname = 'abcDB' or HostName not in ('01-VM','02-VM','03-VM')
--The above hostname is loadbalanced webserver.
UPDATE ##temp set
lastbatch = Convert(DateTime, Convert(VarChar(4), Year(GetDate())) + '/' + lastbatch)
SELECT spid,
lastbatch from ##temp where
lastbatch < (getdate() - @TimeElapsed)
--Check for suspended transaction for last 1 hour.
IF (select count(*) from ##temp where lastbatch < (getdate() - @TimeElapsed) and Status=@TRANSACTION_STATUS)
<> 0
BEGIN
-- Generate output files
SET NOCOUNT ON
DECLARE @spid varchar(5)
DECLARE @sql varchar(200)
DECLARE @sql2 varchar(200)
select @spid = rtrim(spid) from ##temp where lastbatch < (getdate() - @TimeElapsed) and Status=@TRANSACTION_STATUS
PRINT 'Start
Processing'
-- Kill the rogue process
PRINT 'Process to be
killed is: ' + @spid
DECLARE @cmd varchar(10)
select @cmd = 'kill ' + @spid
Print @cmd
--Kill Process
exec (@cmd)
END
drop table ##temp
--select *
from ##temp
END
Sunday, March 29, 2015
Production Support Incident 1. SQL Server Suspended Transaction And IO Wait Issue
This is the most critical findings when there is issue with application downtime.
Application: CMS System- Content Management System
Technology: Custom Asp.net
Scenario: For any CMS system , the caching plays a very essential role. To improve overall user experience and responsive of the system , as a thumbrule and architecure design norms the CMS system should be always initialized by caching. The system content is cached one time so that there is no more chatty communication with SQL server or for that matter with database. This is important as the content in CMS website public facing internet website most of the content is global and applicable for all users. In such scenario the best practice is to cache the content and most common element one time during overall website lifecyle throughout a day.
So when we consider caching below set of design principle must be taken care:-
Life cycle of caching-Age of caching
Frequency and timeline when Business user changing content so that the changes reflects during business as usual.
Warm up caching option in IIS to reduce overall users impact on cache expiration.
Importantly the amount of data cached .Impact on w3p process in IIS, CPU utilization and heap memory fot which sql query is executed.
Mission critical application keep logic outside of application layer..keep it in database for quick fix and resolution . If logic is embedded in business logic with linq query within application layer, Consider hugh business impact and application downtime.
1. Quick Checks:
USE master;
GO
EXEC sp_who2 'active';
GO
If there is suspended transaction SPID then there is serious problem. if suspended transaction is not getting clear within 10 secs then there is potential issue with memory or execution completion of query
2. Quick Checks async_network_io wait in sql server
http://blogs.msdn.com/b/joesack/archive/2009/01/09/troubleshooting-async-network-io-networkio.aspx
3. Quick Checks Page latch above 20
http://blogs.msdn.com/b/askjay/archive/2011/07/08/troubleshooting-slow-disk-i-o-in-sql-server.aspx
http://www.jasonstrate.com/2010/09/index-black-ops-part-2-page-io-latch-page-latch/
SELECT session_id, wait_type, resource_description FROM sys.dm_os_waiting_tasksWHERE wait_type LIKE 'PAGELATCH
Resolution:
Either Optimize query
Or Increase RAM of Sql server OS box.
Application: CMS System- Content Management System
Technology: Custom Asp.net
Scenario: For any CMS system , the caching plays a very essential role. To improve overall user experience and responsive of the system , as a thumbrule and architecure design norms the CMS system should be always initialized by caching. The system content is cached one time so that there is no more chatty communication with SQL server or for that matter with database. This is important as the content in CMS website public facing internet website most of the content is global and applicable for all users. In such scenario the best practice is to cache the content and most common element one time during overall website lifecyle throughout a day.
So when we consider caching below set of design principle must be taken care:-
Life cycle of caching-Age of caching
Frequency and timeline when Business user changing content so that the changes reflects during business as usual.
Warm up caching option in IIS to reduce overall users impact on cache expiration.
Importantly the amount of data cached .Impact on w3p process in IIS, CPU utilization and heap memory fot which sql query is executed.
Mission critical application keep logic outside of application layer..keep it in database for quick fix and resolution . If logic is embedded in business logic with linq query within application layer, Consider hugh business impact and application downtime.
1. Quick Checks:
USE master;
GO
EXEC sp_who2 'active';
GO
If there is suspended transaction SPID then there is serious problem. if suspended transaction is not getting clear within 10 secs then there is potential issue with memory or execution completion of query
2. Quick Checks async_network_io wait in sql server
http://blogs.msdn.com/b/joesack/archive/2009/01/09/troubleshooting-async-network-io-networkio.aspx
3. Quick Checks Page latch above 20
http://blogs.msdn.com/b/askjay/archive/2011/07/08/troubleshooting-slow-disk-i-o-in-sql-server.aspx
http://www.jasonstrate.com/2010/09/index-black-ops-part-2-page-io-latch-page-latch/
SELECT session_id, wait_type, resource_description FROM sys.dm_os_waiting_tasksWHERE wait_type LIKE 'PAGELATCH
Resolution:
Either Optimize query
Or Increase RAM of Sql server OS box.
Thursday, March 19, 2015
Production Support Security Vulnerability Attack
Production Support
The production support is always a touch job to do . The development is a lean process and it follows the timeline, process, planning and execution within the given timeline. There is liberty to give estimation and do planning whereas with support the planning is never the case. One can never know what next.Security vulnerability sometimes taken lightly in support production and there is always a kind of disconnect among different groups like application, database and infrastructure support. When these groups work in a very disconnected mode and communication channel is not so apparent among them then there is a chance of high lapse in support paralysis.
Poddle Attack
Unused certificates
Check for expired SSL certificates.
Step by step of how
to disable SSL V3.
Use the following site to see if your site is poodle free.
You need to get GRADE A after you have applied the
fix.
DOS-DDOS- Distributed Denial of Service
Look out of requests from most common source . Someone must be screwing your system calling /loading or making requests to your website. If you check netstat, IIS logs, windows event application logs, webstats or google analytics something which gives you a indication that there is something wrong with your application. This will tell you the unusual behaviour within the systems when requests common to your server from most common sources.
There are chances your application login attempts of all users will be exhausted and thus users accounts are locked. This is a very huge business impact. Just imagine if this is your E-commerce or banking or financial sites. The day loss of business would be enormous. Hence we have something called captha introduced in early web world to tackle this.
Sr.No
|
Period
|
User Session
|
1
|
Diwali
|
4,00,000
|
2
|
Christmas
|
2,00,000
|
3
|
Normal Day
|
50,000
|
Check the size of iis log . Compare with previous days and can help you analyse the situations more clearly.
Saturday, January 24, 2015
Ghostery Makes it easy for you
Ghostery is such a handy tool that makes our life easy when it comes to security. You can find and able to block all external sources or third party analytics that fetches source data from your website.
Ghostery is an add-ons available for chrome, safari, firefox. Check out cool stuff.
Ghostery is an add-ons available for chrome, safari, firefox. Check out cool stuff.
Convert Timezone UTC to Local Time e.g TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")
Convert UTC to Local TimeZone
public class TimeZoneConvertorHelper
{
private static readonly TimeZoneInfo IndiaTimeZone;
static TimeZoneHelper()
{
IndiaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
}
public static DateTime GetCurrentMelbourneDateTime()
{
return TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, IndiaTimeZone);
}
}
Big Debate: Sticky Session
Sticky Session
Cautions decision to be taken when enabling sticky session . Checks to be made:-
1. Load balanced server
2.Users session distribution across load balanced server.
3. Round Robin distribution
Warnings
- When sticky session enabled , requests are not evenly distributed.
- Sticky sessions are always good if there is not much session values/data for each users.
- RAM utilization may be high as compared to CPU
Options:
Cloud : Elastic Load balancing
Enable sessions based on application instances or node.
Web API :Utility To read Json output From WebResponse
Introduction
The below utility fetches the output from API request through HTTP in JSON format.
public static class JsonRequestStreamUtility
{
public static WebRequest CreateRequest(string url, string method = WebRequestMethods.Http.Get, string body = null)
{
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = method;
webRequest.Accept = "application/json";
webRequest.Headers.Add("Accept-Charset", "utf-8");
webRequest.ContentType = "application/json";
webRequest.Proxy = new System.Net.WebProxy()
{
Address = new Uri("xyz"),
UseDefaultCredentials = true,
};
if (body == null)
return webRequest;
using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
{
streamWriter.Write(body);
}
return webRequest;
}
public static string ExecuteJsonResponseStream(WebRequest webRequest)
{
if (webRequest == null) throw new ArgumentNullException("webRequest");
try
{
// Get the stream associated with the response.
Stream receiveStream = webRequest.GetResponse().GetResponseStream();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
return readStream.ReadToEnd();
}
catch (WebException we)
{
return string.empty;
}
}
}
Sunday, October 19, 2014
Cookieless Session Vs Cookie Session
Reconstructed MSDN Understanding:-
Simple E.g. You go in pub and you handover your jacket in a counter .To get your jacket back you get some token as a reference. Similarly we have session id which is generated on request made to server and it is placed cookies.
Quick Take:-
Cookie Session
1. Cookie store session id and it identify session data from server for each request and response. User agent browser to server.
2. If Session object is not created or used apart from session_start , for each new requests it creates new session IDs. Hence it is require to create session object either in session_start or any part of application.
Cookie Less Session
1. In this case session id is static and remain same for entire session period
2. Session id is stored in URL for each request and response.
There can be possibilty when there is device where cookies are disabled and in such scenario we can make use of Cookie less session. There is feature itself in asp.net by using Autodetect for UseDeviceProfile.
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid(v=vs.110).aspx
http://www.iis.net/learn/application-frameworks/scenario-build-an-aspnet-website-on-iis/planning-step-2-plan-asp-net-settings
http://msdn.microsoft.com/en-us/library/vstudio/ms178581(v=vs.100).aspx
http://blogs.msdn.com/b/jaskis/archive/2009/12/23/securing-session-id-asp-asp-net.aspx
Simple E.g. You go in pub and you handover your jacket in a counter .To get your jacket back you get some token as a reference. Similarly we have session id which is generated on request made to server and it is placed cookies.
Quick Take:-
Cookie Session
1. Cookie store session id and it identify session data from server for each request and response. User agent browser to server.
2. If Session object is not created or used apart from session_start , for each new requests it creates new session IDs. Hence it is require to create session object either in session_start or any part of application.
Cookie Less Session
1. In this case session id is static and remain same for entire session period
2. Session id is stored in URL for each request and response.
There can be possibilty when there is device where cookies are disabled and in such scenario we can make use of Cookie less session. There is feature itself in asp.net by using Autodetect for UseDeviceProfile.
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid(v=vs.110).aspx
http://www.iis.net/learn/application-frameworks/scenario-build-an-aspnet-website-on-iis/planning-step-2-plan-asp-net-settings
http://msdn.microsoft.com/en-us/library/vstudio/ms178581(v=vs.100).aspx
http://blogs.msdn.com/b/jaskis/archive/2009/12/23/securing-session-id-asp-asp-net.aspx
Saturday, October 18, 2014
FactFile SessionID in Asp.net and SqlServer SessionState
Facts to be remember. While dealing with session always keep below factfile into consideration.
I created a variable in the
Session_Start in the global.asax file:var sessionID = Session.SessionID;
ASP.NET generated : lehxv4so4ioi2gqqaxtjzhyo
SQL Server saved : lehxv4so4ioi2gqqaxtjzhyo84497b6f
lehxv4so4ioi2gqqaxtjzhyo84497b6f
in bold is your sessionid and in italics is the application id
the extra 8 bytes are the applicationid
SQL Server Session Tables
ASPStateTempSessions
ASPStateTempApplications
SQL Server Session Database
tempdb database in SQL Server by default
- Very Very Imp never use Tempdb for outproc session.
- In out proc mode session_end never calls, no use if you apply any debug or diagnostics pointers.
If we using webfarm and out proc session, ensure machine key across server instance is unique.
http://www.codeproject.com/Articles/104082/Configuring-ASP-session-state-on-SQL-server
http://stackoverflow.com/questions/22228972/strange-timeout-in-sitecore-7
http://blogs.msdn.com/b/akshayns/archive/2008/09/29/common-reasons-for-the-session-loss-issue-in-asp-net-applications.aspx
Cookie Container
http://www.developer.com/net/asp/article.php/10917_3595766_3/Storing-Session-State-in-a-SQL-Server-Database.htm
http://weblogs.asp.net/stevewellens/using-session-state-in-a-web-service
http://weblogs.asp.net/jongalloway/10-things-asp-net-developers-should-know-about-web-config-inheritance-and-overrides
http://www.c-sharpcorner.com/UploadFile/1d42da/using-session-state-in-a-web-service/
http://blogs.msdn.com/b/tess/archive/2008/11/06/troubleshooting-appdomain-restarts-and-other-issues-with-etw-tracing.aspx
http://www.codeproject.com/Articles/35119/Using-Session-State-in-a-Web-Service
http://msdn.microsoft.com/en-us/library/aa480509.aspx
http://seejoelprogram.wordpress.com/2008/11/10/maintaining-aspnet-session-state-in-an-ajax-application/
http://stackoverflow.com/questions/24707339/how-to-make-a-session-enabled-asp-net-web-service-work-with-an-ajax-client-in-a
http://devpinoy.org/blogs/willydavidjr/archive/2008/06/13/using-asp-net-session-state-in-a-web-service.aspx
IIS Debugging -WET Tracing For IIS
IIS Debugging
Whenever you have to check the request serving and find out how http pipeline processed at kernel aswell as user mode level using this options
Ofcourse HTTPERR log , httpsys and iislogs and Perfmon will be of great use. But this comes very handy.
c:\>
logman stop httptrace -ets
The command
completed successfully.
c:\>
tracerpt.exe trace-output.etl -of XML -o trace-output.xml
c:\>
logman start httptrace -p Microsoft-Windows-HttpService 0xFFFF -o
trace-output.etl -ets
The
command completed successfully.
Session Variables vs Session Timeout vs Session Mode
Recent time i had tough time dealing with sessions in asp.net , especially when it is product related to sitecore where we have complex setup with mulitple instance within same app domain and website.
The reason why I m pondering on session variables vs Session timeout vs session mode is something we need to be extra careful when identifying the problem at the same time understanding it. This is where you start your right investigations.
What I know, as this session things are such we rarely come across with issues and it becomes history by the time we forget the concepts inline with asp.net same applies to cookies and caching. We tend to forget them as we don't apply them very frequently. Telling long story shorts!
We got into trouble with session and we assumed and presummed it was session timeout -expiry issue as it is getting timeout after every 2 minutes. This is what we have been thinking and taking are investigation ahead.
Then later stage we realized we haven't gave much thoughts session mode.
Remember there is settings for session IIS aswell as in web.config , sometimes it do not sync. Check that aswell.
Coming back session mode, we have two session mode one In-Proc and Out-Proc
Now Out-Proc can be two ways to setup one is SessionState= StateServer that is done through asp.net state Service in Run-> Services.msc and it is kind of window service run outside of IIS.Hence there is no question of app pool recycle or app domain restart or bin changes as it is out proc your session still alive for given time period.
Same applies for out proc mode with SessionState= SQLServer where we store session in sql server. In Master aspnetTempsession.There is two tables where it has applicationsession table and its corresponding mapping in aspnetTempsession. May be one can look into this in details..SQL Server Agent plays crucial role as there is job which manages session managment at large.
http://www.c-sharpcorner.com/UploadFile/2124ae/out-of-process-session-state-in-state-server-in-Asp-Net/
The above is some overview as I learnt it in hard way after such a long experience in .net
After understanding the above concepts we got to know we were following wrong directions as we didn't got our problem statement right.
My application was using Out Proc and problem still persisted , timeout was again 2 minutes and still we haven't got into the bottom of it.
Soon we came up with different strategy we added trace response.write in staging env we just capture session ID and aswell as did lookup what happing in background using sql profiler trace.
Here is the catch!
We found that Session.ID still available as is for timeout period=20 minutes whereas session variables are setting it to null every time after 2 minutes..My investigation and probing --debugging the root cause is still on-- Need to reveal yet!
?
Hence I kept emphasing on verdict of be Sure, doubly sure what is it , is it related to session expiry or Session variables or session mode(Incorrectly set)
We you are using In- Proc,
Check Tezz Fernandez blogs. for sure we will get some idea how to resolve your issues.
http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx
Some Scott Gutrie Way
http://weblogs.asp.net/scottgu/433194
On Some Tracing Event window Tracing
The reason why I m pondering on session variables vs Session timeout vs session mode is something we need to be extra careful when identifying the problem at the same time understanding it. This is where you start your right investigations.
What I know, as this session things are such we rarely come across with issues and it becomes history by the time we forget the concepts inline with asp.net same applies to cookies and caching. We tend to forget them as we don't apply them very frequently. Telling long story shorts!
We got into trouble with session and we assumed and presummed it was session timeout -expiry issue as it is getting timeout after every 2 minutes. This is what we have been thinking and taking are investigation ahead.
Then later stage we realized we haven't gave much thoughts session mode.
Remember there is settings for session IIS aswell as in web.config , sometimes it do not sync. Check that aswell.
Coming back session mode, we have two session mode one In-Proc and Out-Proc
Now Out-Proc can be two ways to setup one is SessionState= StateServer that is done through asp.net state Service in Run-> Services.msc and it is kind of window service run outside of IIS.Hence there is no question of app pool recycle or app domain restart or bin changes as it is out proc your session still alive for given time period.
Same applies for out proc mode with SessionState= SQLServer where we store session in sql server. In Master aspnetTempsession.There is two tables where it has applicationsession table and its corresponding mapping in aspnetTempsession. May be one can look into this in details..SQL Server Agent plays crucial role as there is job which manages session managment at large.
http://www.c-sharpcorner.com/UploadFile/2124ae/out-of-process-session-state-in-state-server-in-Asp-Net/
The above is some overview as I learnt it in hard way after such a long experience in .net
After understanding the above concepts we got to know we were following wrong directions as we didn't got our problem statement right.
My application was using Out Proc and problem still persisted , timeout was again 2 minutes and still we haven't got into the bottom of it.
Soon we came up with different strategy we added trace response.write in staging env we just capture session ID and aswell as did lookup what happing in background using sql profiler trace.
Here is the catch!
We found that Session.ID still available as is for timeout period=20 minutes whereas session variables are setting it to null every time after 2 minutes..My investigation and probing --debugging the root cause is still on-- Need to reveal yet!
?
Hence I kept emphasing on verdict of be Sure, doubly sure what is it , is it related to session expiry or Session variables or session mode(Incorrectly set)
We you are using In- Proc,
Check Tezz Fernandez blogs. for sure we will get some idea how to resolve your issues.
http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx
Some Scott Gutrie Way
http://weblogs.asp.net/scottgu/433194
On Some Tracing Event window Tracing
c:\>
logman stop httptrace -ets
The command
completed successfully.
c:\>
tracerpt.exe trace-output.etl -of XML -o trace-output.xml
c:\>
logman start httptrace -p Microsoft-Windows-HttpService 0xFFFF -o
trace-output.etl -ets
The
command completed successfully.
Signing Off
Santosh Poojari
Windows Azure Storage Issue with Micirosoft.DataServices.Client loading assembly
Summary-
This problem is most common with windows Azure SDK version where it get conflicts with versions of dll related to Micirosoft.DataServices.Client . As a temporary get away to this problem is to just exclude it from runtime tags in your app.config or web.config. Beware you need again need to fix if you have to deploy this to production environment.
Sometime update to Nuget package doesn't work the way we want.
http://www.dinohy.com/post/2014/04/02/Windows-Azure-Could-not-load-file-or-assembly-MicrosoftDataServicesClient-Version=5600.aspx
Friday, September 5, 2014
Wow ! Background Task in Separate thread in Asp.net web form
Its unfortunate that I never used threading to that extent as most of my work involved in web platform with very little to do with threading and task parallelism. Still there are cases where this Background Task can come handy. Now it depends.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//We started this task in separate thread which will not interfere in web page usual activity.
//We can still perform all operations and this below task will run in background.
BackgroundTest longTest = new BackgroundTest(50);
Thread backgroundThread = new Thread(new ThreadStart(longTest.RunLoop));
backgroundThread.Name = "BackgroundThread";
backgroundThread.IsBackground = true;
backgroundThread.Start();
Label1.Text = "end";
}
///
/// Non Stoppable Button click..I mean we can still perform this operation
/// independent of below background thread.
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//We started this task in separate thread which will not interfere in web page usual activity.
//We can still perform all operations and this below task will run in background.
BackgroundTest longTest = new BackgroundTest(50);
Thread backgroundThread = new Thread(new ThreadStart(longTest.RunLoop));
backgroundThread.Name = "BackgroundThread";
backgroundThread.IsBackground = true;
backgroundThread.Start();
Label1.Text = "end";
}
///
/// Non Stoppable Button click..I mean we can still perform this operation
/// independent of below background thread.
///
///
///
protected void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("Som Button Click");
}
///
/// Background Thread
///
class BackgroundTest
{
int maxIterations;
public BackgroundTest(int maxIterations)
{
this.maxIterations = maxIterations;
}
public void RunLoop()
{
String threadName = Thread.CurrentThread.Name;
for (int i = 0; i < maxIterations; i++)
{
Thread.Sleep(25000);
}
System.IO.File.AppendAllText("E:/test", DateTime.Now.ToString());
}
}
}
Subscribe to:
Posts
(
Atom
)