Saturday, October 18, 2008

App_Offline.htm .... Taking an ASP.NET 2.0 application offline

Sometimes what happens is , when you are working on some maintainence stuff on your website , then you need to STOP the application from functioning. This could prove to be a tedious task . So as a solution to this ,comes another amazing feature of Visual Studio.Net which we will see in the coming lines below.

Create a file named "app_offline.htm" in the root of the application . When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application. So when you are done updating the site, just delete the file and it will come back online.

So if you use the app_offline.htm feature, you should make sure you have at least 512 bytes of content within it to make sure that your HTML shows up to your users.

For example :

This page is U N D E R C O N S T R U C T I O N !!. Please visit after sometime. Thank You !!




I hope this article helps someone or the other someday. :-)

Wednesday, August 6, 2008

SQL - CLR Integration in Visual Studio .NET

The SQL – CLR integration feature has been into existence since VS 2005. The most amazing feature of this is, frankly speaking , you can create a dll using VS.Net and then you can access that dll’s logic in SQL Server 2005.. Wanna know more about this , then lets get it started…

The first and foremost point is to "ENABLE" the CLR functionality in Sql Server 2005 ,( 'coz by default it's DISABLED) which you can do it in this way ... Write the below given commands in the Sql Server Management Studio IDE in the database where you want to perform this.



sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO

Step1: Create a SQL Server Database Project in Visual Studio .





I named it as "My Project", you can name it as you like.



Now it asks for a Database connection instance ,like the one shown below.





Select your desired database conection or create a new one by clicking " Add New Reference".




Step2: Right Click on the Project name and add a new item " User-Defined Function" ( I have used function here, you can create a Stored Procedure or trigger as well ... depending on your requirement ).






By default , the Function Class contains a function returning "Hello " . So we'll use that one as our function.


Step 3 : Now , BUILD the project and then the dll is created for that project in its root folder.


Now , right click on the project and click "Deploy" . This will deploy your project onto the instance of Sql Server and also creates an ASSEMBLY with the same name as per the name of your project's dll. for eg; here it's name is MyProject .





To check out whether the assembly has been created or not , execute this in Sql Server Management Studio IDE ,


Select * from sys.Assemblies


This will display the registered assemblies in that database .


Step 4: As of now the assembly is created, so now we need to create a FUNCTION that references that assembly .



CREATE function MyFunction ()
returns nvarchar(15)
AS EXTERNAL NAME MyProject.[UserDefinedFunctions].Function1


Note : MyFunction () is the name of the function you want to create.


MyProject is the name of the Assembly ,which got created when we click the DEPLOY option .


UserDefinedFunctions is the name of the Parent Class present in the file Function1.cs


Function1 is the name of the function present in the file Function1.cs


Execute the above code in Sql Server Management Studio IDE and now your Function is ready to be used . Check it out by executing the below command,


Select dbo.MyFunction ()


Now this returns the output as "Hello" ..


From this article , we have learnt as to how one can use the SQL - CLR Integration feature of Visual Studio .Net.


Hope you liked the article . Till then keep rocking and enjoy programming .



Wednesday, May 14, 2008

Disable Dates in a Calendar

From my previous experiences , what i have found out is that sometimes we need to disable the previous and coming dates in a calendar control. So finally i thought to post it out. It goes like this....,



protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date< DateTime.Today)
{
e.Day.IsSelectable = false;
e.Cell.ToolTip = "This date is not available";
}
else if (e.Day.Date> DateTime.Today)
{
e.Day.IsSelectable = false;
e.Cell.ToolTip = "This date is not available";
}
}

Keep rockiin........

Wednesday, May 7, 2008

Detecting User's IP Address

If your website contains sensitive data and you don't want any spamming or any malicious use of your website ,then one thing you can do is to keep a track of the visiting user's system IP and this can be done in some easy steps given below,


string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();


Now set the value of clientIPAddress to either a Textbox or label or any control as per your requirement.

Sunday, May 4, 2008

Useful HTML Meta Tags

To be precise, HTML Meta tags are quite powerful in the sense that using these tags one set the page refresh at a specific time and also can put your website at the top level when someone searches (*using Google Search or any other Search engine) for a specific thing related to your website..

Have a look at it and feel the difference.. Hope this helps..

http://www.i18nguy.com/markup/metatags.html


Happy Programming :)

Wednesday, April 30, 2008

Using the Google search from ASP.NET

I hope that every one has thought of using the infamous Google Search in their projects/applications but couldn't figure out as to how to do this..

Fine... now you can integrate Google Search into your applications..

Check out the below article and figure out the truth..

http://www.communitymx.com/content/article.cfm?page=1&cid=E8E8CE970C6AB073


Happy Programming. :)

Saturday, April 19, 2008

Why do ASP.NET AJAX page methods have to be static?

This has been a question of concern for quite sometime now.. So to solve the issue , i suggest you to have a look at the below article .

Hope you like it . :)

http://encosia.com/2008/04/16/why-do-aspnet-ajax-page-methods-have-to-be-static/

Wednesday, April 16, 2008

Code Conversion

Having problems while converting your code from C# to VB or vice-versa ?? Then i suggest you to use http://www.codechanger.com.

Have a look at it and try it ...


Happy Programming :)

Easy to understand ASP.NET Tutorials

Well... today while sitting in my office , i thought that what is that is needed for a new programming soul to get started with coding . Huh.... but if you want to have a look at an easier way of programming, then check out http://www.aspnettutorials.com

Happy Programming :)

Tuesday, April 15, 2008

Dynamic Site Layout and Style Personalization with ASP.NET

These days many websites offer customisable features and one of them is setting themes according to user preferences. In other words, we can say that generating the look and feel of the website as per user requests.
So now the big question arises as to how one can achieve/implement this feature. Scott Guthrie has explained this in a very conventional way. Have a look at it..

http://weblogs.asp.net/scottgu/archive/2006/07/22/Recipe_3A00_-Dynamic-Site-Layout-and-Style-Personalization-with-ASP.NET--.aspx

Monday, April 14, 2008

ASP.NET Page Life Cycle

Each request for a Microsoft® ASP.NET page that hits Microsoft® Internet Information Services (IIS) is handed over to the ASP.NET HTTP pipeline. The HTTP pipeline is a chain of managed objects that sequentially process the request and make the transition from a URL to plain HTML text happen. The entry point of the HTTP pipeline is the HttpRuntime class. The ASP.NET infrastructure creates one instance of this class per each AppDomain hosted within the worker process...

For a detailed scenario of Page Life Cycle, just go through
http://msdn2.microsoft.com/en-us/library/aa479007.aspx

Sunday, April 6, 2008

Tip/Trick:Url Rewriting with ASP.NET

For dynamically re-writing URLs or to publish cleaner URL end-points in your ASP.NET applications , just have a look at this article by Scott Guthrie.

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Wednesday, April 2, 2008

Displaying Date in many formats Using Javascript

Hi folks,

Just check out the below link for some cool stuff on how to display date & time using Javascript in different formats.

http://www.javascriptmall.com/jsc/jsC4Udate.htm#DateTime11

Two Rows of Tab Headers in an AJAX Tab Control

There has been much talk about the AJAX's Tab control. But by default, it displays all the Tab containers in one line only. So how to make it multi lined. For doing this. check out the below article .



http://www.narizvi.com/blog/post/Two-rows-of-tab-headers-in-TabContainer-in-Ajax-Control-Toolkit.aspx

Thursday, March 27, 2008

Don’t run production ASP.NET Applications with debug=”true” enabled

One of the things you want to avoid when deploying an ASP.NET application into production is to accidentally (or deliberately) leave the switch on within the application’s web.config file.

Doing so causes a number of non-optimal things to happen including:

1) The compilation of ASP.NET pages takes longer (since some batch optimizations are disabled)
2) Code can execute slower (since some additional debug paths are enabled)
3) Much more memory is used within the application at runtime
4) Scripts and images downloaded from the WebResources.axd handler are not cached

This last point is particularly important, since it means that all client-javascript libraries and static images that are deployed via WebResources.axd will be continually downloaded by clients on each page view request and not cached locally within the browser. This can slow down the user experience quite a bit for things like Atlas, controls like TreeView/Menu/Validators, and any other third-party control or custom code that deploys client resources. Note that the reason why these resources are not cached when debug is set to true is so that developers don’t have to continually flush their browser cache and restart it every-time they make a change to a resource handler (our assumption is that when you have debug=true set you are in active development on your site).

When is set, the WebResource.axd handler will automatically set a long cache policy on resources retrieved via it – so that the resource is only downloaded once to the client and cached there forever (it will also be cached on any intermediate proxy servers). If you have Atlas installed for your application, it will also automatically compress the content from the WebResources.axd handler for you when is set – reducing the size of any client-script javascript library or static resource for you (and not requiring you to write any custom code or configure anything within IIS to get it).

What about binaries compiled with debug symbols?

One scenario that several people find very useful is to compile/pre-compile an application or associated class libraries with debug symbols so that more detailed stack trace and line error messages can be retrieved from it when errors occur.

The good news is that you can do this without having the have the switch enabled in production. Specifically, you can use either a web deployment project or a web application project to pre-compile the code for your site with debug symbols, and then change the switch to false right before you deploy the application on the server.

The debug symbols and metadata in the compiled assemblies will increase the memory footprint of the application, but this can sometimes be an ok trade-off for more detailed error messages.

The Switch in Machine.config

If you are a server administrator and want to ensure that no one accidentally deploys an ASP.NET application in production with the switch enabled within the application’s web.config file, one trick you can use with ASP.NET V2.0 is to take advantage of the section within your machine.config file.

Specifically, by setting this within your machine.config file:







You will disable the switch, disable the ability to output trace output in a page, and turn off the ability to show detailed error messages remotely. Note that these last two items are security best practices you really want to follow (otherwise hackers can learn a lot more about the internals of your application than you should show them).

Setting this switch to true is probably a best practice that any company with formal production servers should follow to ensure that an application always runs with the best possible performance and no security information leakages. There isn’t a ton of documentation on this switch – but you can learn a little more about it here.