How the session work in asp.net?

ASP.NET uses a cookie to track users. When you try to write something to the session for the first time a cookie is sent to the client, something like ASP.NET_SessionId. This cookie is sent by the client on subsequent requests. Thanks to this cookie the server is able to identify the client and write/read the … Read more

How to initialize a list with constructor?

Using a collection initializer From C# 3, you can use collection initializers to construct a List and populate it using a single expression. The following example constructs a Human and its ContactNumbers: var human = new Human(1, “Address”, “Name”) { ContactNumbers = new List<ContactNumber>() { new ContactNumber(1), new ContactNumber(2), new ContactNumber(3) } } Specializing the … Read more

how to solve Error cannot add duplicate collection entry of type add with unique key attribute ‘value’ in iis 7

IIS7 defines a defaultDocument section in its configuration files which can be found in the %WinDir%\System32\InetSrv\Config folder. Most likely, the file index.aspx is already defined as a default document in one of IIS7’s configuration files and you are adding it again in your web.config. I suspect that removing the line <add value=”index.aspx” /> from the … Read more

Forms Authentication Timeout vs Session Timeout

To be on the safe side: TimeOut(Session) <= TimeOut(FormsAuthentication) * 2 If you want to show page other than specified in loginUrl attribute after authentication timeout you need to handle this manually as ASP.NET does not provide a way of doing it. To achieve #2 you can manually check the cookie and its AuthenticationTicket for … Read more

Create Text File Without BOM

Well it writes the BOM because you are instructing it to, in the line Encoding utf8WithoutBom = new UTF8Encoding(true); true means that the BOM should be emitted, using Encoding utf8WithoutBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); writes no BOM. My objective is create a file using UTF-8 as Encoding and 8859-1 as CharSet Sadly, this is not … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)