Asp.Net : Unable to make the session state request to the session state server

April 24, 2015

Asp.Net : Unable to make the session state request to the session state server

Unable to make the session state request to the session state server

That error message means the ASP.NET State service is not running in services.msc

Advertisements

Asp.net – try catch finally notes

March 27, 2014

The code inside a finally block will get executed regardless of whether or not there is an exception.

http://www.codeproject.com/Articles/154121/Using-Try-Catch-Finally

Exception handling in C#. In the below code

Try
{

//Throwing Error
}
Catch
{
//Getting Caught
}
Finally
{
int x =3;
}

int x = 5 ;

In Try after throwing an Error which is caught in Catch ,After that Finall Block Executes with Assignment of x=3. and after that next line x=5 is also executed.Program not getting terminated..What might be the reason ?


Asp.net file upload control error

January 4, 2014

HTTP Error 404.13 – Not Found : The request filtering module is configured to deny a request that exceeds the request content length – See more at: http://www.shubho.net/2011/01/http-error-40413-not-found-request.html#sthash.dKksj9Q8.dpuf

http://www.shubho.net/2011/01/http-error-40413-not-found-request.htmlA

 

 

<requestLimits maxAllowedContentLength=”2048000000″></requestLimits>

 

http://www.shubho.net/2011/01/http-error-40413-not-found-request.html

 

I was developing an application that allows user to upload files to the server using the <asp:FileUpload/> control. In order to make sure that users can upload large files, I configured the web.config as follows to allow larger files to be uploaded (The default setting is 4 MB):
1
<httpRuntime maxRequestLength="512000"/><!--To allow up to 500MB-->
While testing the file upload functionality from within the visual studio development server (Right clicking on the aspx file and selecting browse), I found it working quite fine. But surprisingly, after hosting the Asp.net web site onto IIS (IIS 7), I found the file uploading functionality was no longer working, and, it was broken while trying to upload large files (I was trying with a file over 40MB in size). Following is the screen shot of the error message that I got:

Figure : The error message from IIS while trying to upload a large file
The error page also suggested me to do the followings:
“Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in the applicationhost.config or web.config file.”
So, as suggested, I did the following configuration in the web.config of my Asp.net web site(By setting maxAllowedContentLength value in Bytes):
1
2
3
4
5
6
7
8
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="512000"></requestLimits>
    </requestFiltering>
  </security>
</system.webServer
1
Guess what, it didn’t work out! After modification when I tried to upload the file again, the same problem occured again. What happened?
According to the error message, the web.config or applicationhost.config should be configured according to the above suggestion. Modifying web.config didn’t work out. So, the applicationhost.config could be modified to see what happens.

Wait a minute! the applicationhost.config is the configuration file of IIS (IIS7.0 or heigher). Does that mean IIS has a Request size validation?

Yes it has. Until IIS 7.0 there was no Request size validation, but since IIS 7.0, the Request length is verified by IIS first, before deliverying the Request to Asp.net.
So, to be true, it doesn’t really make any sense to increase the maxAllowedContentLength value in web.config. The Request dies even before reaching the Asp.net. So, whatever is to be configured, it has to happen at IIS.
Well, as I figured out, there are two ways you can configure this value in IIS:
1. Configuring the applicationhost.config
Open the %WINDIR%\System32\inetsrv\config\applicationHist.config in editor and specify the following configuration within the security/requestFiltering section(By setting maxAllowedContentLength value in Bytes):
1
2
3
<requestFiltering>
      <requestLimits maxAllowedContentLength="512000000"></requestLimits>
</requestFiltering>
Note:
Modifying the above configuration worked for me in one PC (Running Windows 7+IIS 7.0), but, didn’t work on another one (Running Windows Vista + IIS 7.0). After configuring the applicationHost.config file, I tried to upload the large file and the same error message was appearing again. I don’t know why, but, if you have the same experience, applying the following approach (Configuring via IISManager) would definitely work. 
2. Configuring via IISManager
Open the IIS Manager and select the site or application you need to configure in the left panel
Select “Features View” and double click on the “Request Filtering” icon.
Figure : Request Filtering
Note :
If you can’t find the “Request Filtering”icon, you need to install the IIS Administration Pack from this link : http://www.iis.net/download/AdministrationPack. This is a lightweight installation which shouldn’t take too much time on a decent internet speed.
Double clicking on the “Request Filtering”icon will bring up the Request filtering configuration window. Right click on the window and select the “Edit Feature Settings” option:
Figure : Edit Feature Settings option in IIS
Finally, specify the Maximum allowable content length (In Byte) in the following window and click “OK” to save:
Figure : Specifying Maximum allowable content length in Bytes
This worked perfect for me and I was able to upload the large file now without any problem. Hope, this will work for you too 🙂

– See more at: http://www.shubho.net/2011/01/http-error-40413-not-found-request.html#sthash.dKksj9Q8.dpuf


Install a .NET windows service without InstallUtil.exe

December 17, 2013

when i was in client place I got a problem

I need to install a windows service using installutil.exe but there is no visual studio command prompt tool.

http://dotnetstep.blogspot.sg/2009/06/install-window-service-without-using.html

c:\windows\system32\\

sc create ServiceName binPath= “c:\windowservice1\windowservice1.exe”

here ServiceName is userdefined name it can be anything

When creating the service there is a space between the = and ”

ie after binPath= provide a space

Deleting a windows service from command prompt

sc delete ServiceName

Install window service without using installutil

Article is about to install window service without using InstallUtil utility.
Windows XP or Later has command line utility called sc . (This utility talks with service controller and with services from command line).
SC is a window base utility. AS explain in article http://dotnetstep.blogspot.com/2009/06/install-windowservice-using-installutil.html sc does not required ProjectInstaller.

1. Start service using sc
sc start ServiceName

2. Stop serivce
sc stop ServiceName

3. Delete window service
sc delete servicename
Note : During delete call if service is in running state then service is delete when nexttime service is stop or PC restart.

4. Create window service
sc create ServiceName binpath= “c:\windowservice1\windowservice1.exe”

Apart from above many option available . For that just go to command prompt and type sc create /?

For example configure service running account.

sc create servicename binpath= “c:\windowservice1\windowservice1.exe” obj= administratorpassword= pass

 

 

References:

 

watching files in folder console application c#

http://www.codecandle.com/articles/csharp/io/filesystemwatcher-monitoring-the-file-system-events-with-filesystemwacher-class-instance.html

http://www.codeproject.com/Articles/26528/C-Application-to-Watch-a-File-or-Directory-using-F

http://www.csharptutorial.in/2013/04/Csharp.Net-How-To-Monitor-Directory-and-files-using-Csharp-FileSyestemWatcher.html#.UqndUfT6Re4

http://devproconnections.com/net-framework/how-build-folder-watcher-service-c

How to Open Windows Task Scheduler (control panel->administrative tools->task schedulter in windows7)

http://www.dummies.com/how-to/content/how-to-open-windows-task-scheduler.html

http://msdn.microsoft.com/en-us/library/9aackb16(v=vs.110).aspx
debug windows service c# visual studio 2008

http://www.sarin.mobi/2008/08/c-windows-service-visual-studio-2008/

http://mindstick.com/Articles/fd4971ba-7e48-4f1a-9aa1-621748a98e9f/?Windows%20Service
http://www.c-sharpcorner.com/UploadFile/prvn_131971/DebuggingWindowsServices02062006014001AM/DebuggingWindowsServices.aspx

from vs command prompt
C:\Windows\system32>installutil -u E:\Projects\HimalayaPhase2\Phase2\AutoRecManP
rocess\FileWatcherWindowsService\bin\Debug\FileWatcherWindowsService.exe


Understanding Asp.net 2.0 FileUpload Control

August 23, 2013

How to increase the max upload file size in ASP.NET?

<system.web>
    <httpRuntime executionTimeout="3600" maxRequestLength="102400" 
     appRequestQueueLimit="100" requestValidationMode="2.0"
     requestLengthDiskThreshold="10024000"/>
</system.web>

http://www.codeproject.com/Articles/20023/ASP-NET-2-0-FileUpload-Server-Control

Understanding File Size Limitations

Your end users might never encounter an issue with the file upload process in your application, but you should be aware that some limitations exist. When users work through the process of uploading files, a size restriction is actually sent to the server for uploading. The default size limitation is 4MB (4096KB); the transfer fails if a user tries to upload a file that is larger than 4096KB.

A size restriction protects your application. You want to prevent malicious users from uploading numerous large files to your Web server in an attempt to tie up all the available processes on the server. Such an occurrence is called a “denial of service attack.” It ties up the Web server’s resources so that legitimate users are denied responses from the server.

One of the great things about .NET, however, is that it usually provides a way around limitations. You can usually change the default settings that are in place. To change the limit on the allowable upload file size, you make some changes in either the web.config.comments file (found in the ASP.NET 2.0 configuration folder atC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG) or in your application’s web.config file.

In the web.config.comments file, find a node called <httpRuntime>. In this file, you see that the default allowable file size is dictated by the actual request size permitted to the Web server (4096KB). The <httpRuntime> section of theweb.config.comments file is shown in Listing 2.

Listing 2: Changing the File Size Limitation Setting in the web.config File

 Collapse | Copy Code
<httpRuntime 
 executionTimeout="110" 
 maxRequestLength="4096" 
 requestLengthDiskThreshold="80" 
 useFullyQualifiedRedirectUrl="false" 
 minFreeThreads="8" 
 minLocalRequestFreeThreads="4" 
 appRequestQueueLimit="5000" 
 enableKernelOutputCache="true" 
 enableVersionHeader="true" 
 requireRootedSaveAsPath="true" 
 enable="true" 
 shutdownTimeout="90" 
 delayNotificationTimeout="5" 
 waitChangeNotification="0" 
 maxWaitChangeNotification="0" 
 enableHeaderChecking="true" 
 sendCacheControlHeader="true" 
 apartmentThreading="false" />

You can do a lot with the <httpRuntime> section of the web.config file, but two properties — themaxRequestLength and executionTimeout properties — are especially interesting.

The maxRequestLength property is the setting that dictates the size of the request made to the Web server. When you upload files, the file is included in the request; you alter the size allowed to be uploaded by changing the value of this property. The value presented is in kilobytes. To allow files larger than the default of 4MB, change themaxRequestLength property as in the following: maxRequestLength="11000".

This example changes the maxRequestLength property’s value to 11,000KB (around 10MB). With this setting in place, your end users can upload 10MB files to the server. When changing the maxRequestLength property, be aware of the setting provided for the executionTimeout property. This property sets the time (in seconds) for a request to attempt to execute to the server before ASP.NET shuts down the request (whether or not it is finished). The default setting is 90 seconds. The end user receives a timeout error notification in the browser if the time limit is exceeded. If you are going to permit larger requests, remember that they take longer to execute than smaller ones. If you increase the size of the maxRequestLength property, you should examine whether to increase theexecutionTimeout property as well.

If you are working with smaller files, it’s advisable to reduce the size allotted for the request to the Web server by decreasing the value of the maxRequestLength property. This helps safeguard your application from a denial of service attack.

Making these changes in the web.config.comments file applies this setting to all the applications that are on the server. If you want to apply this only to the application you are working with, apply the <httpRuntime> node to theweb.config file of your application, overriding any setting that is in the web.config.comments file. Make sure this node resides between the <system.web> nodes in the configuration file.

404 Errors with FileUpload with IIS7

I was getting some 404 errors while using the FileUpload control. I tested it out on my local machine and  using

<system.web>
<httpRuntime maxRequestLength=”256000″/> <!– request length is in kilobytes –>
</system.web>

worked fine. But once I moved it onto IIS7 everything started freaking out. Turns out IIS7 look for a different setting:

<system.webServer>
<security>
<requestFiltering><requestLimits maxAllowedContentLength=”262144000″ /></requestFiltering> <!– maxAllowedContentLength is in bytes. Defaults to 30,000,000 –>
</security>
</system.webServer>

My searches really only directed me to modifying the system.web, so hopefully this will help someone out.

404 error when uploading large files (4mb+) – asp.net

http://stackoverflow.com/questions/14511798/404-error-when-uploading-large-files-4mb-asp-net


ASP.NET Number validation in Textbox

December 3, 2011

Only Number validation in Textbox of ASP.NET Using Regular Expression validator
Only numbers can enter into that Textbox

We can use Regular expression validator for this:
In the validation expression property keep ^\d+$.

<asp:TextBox ID=”TextBox1″ runat=”server” Style=”z-index: 100; left: 259px; position: absolute;
top: 283px” ValidationGroup=”check”></asp:TextBox>

<asp:RegularExpressionValidator ID=”RegularExpressionValidator1″ runat=”server” ControlToValidate=”TextBox1″
ErrorMessage=”Please Enter Only Numbers” Style=”z-index: 101; left: 424px; position: absolute;
top: 285px” ValidationExpression=”^\d+$” ValidationGroup=”check”></asp:RegularExpressionValidator>
——-

equivalent telerik control
<telerik:RadNumericTextBox ID=”RadNumericTextBox1″ runat=”server” Type=”Number” NumberFormat-DecimalDigits=”0″>
                        </telerik:RadNumericTextBox>
<asp:RequiredFieldValidator ID=”NumercTextBoxRequiredFieldValidator” runat=”server”
Display=”Dynamic” ControlToValidate=”RadNumericTextBox1″ ErrorMessage=”Please, select an year number!” />
<asp:RangeValidator ID=”NumericTextBoxRangeValidator” runat=”server” ControlToValidate=”RadNumericTextBox1″
ErrorMessage=”Year number should be a non negative less than 50.” Display=”Dynamic”
MaximumValue=”50″ MinimumValue=”0″ Type=”Integer” />