Sunday, March 15, 2015

How to create One ASP.NET application / What is One ASP.NET?

Did you ever face an interview question “What is One ASP.NET?” Did you ever create One ASP.NET web application? Do you know how to create One ASP.NET web application? All these questions will be answered here.

First lets find the answer for “What is One ASP.NET?”

As the name suggests One ASP.NET, it is a one ASP.NET project for multiple .NET supported technologies. Now you have MVC, WEB API, ASP.NET etc where you can create web application. How about creating one ASP.NET project and integrating all these technologies. Microsoft was reading our developers mind and they came up with ONE ASP.NET concepts in the same way what we all are thinking.

Now you just need to create one web project and then you can decide what technology you wanted to use at any time without any migration from one to another. Which means you can pick the technology at any time no need to decide everything in advance.

In order to create One ASP.NET project you should have Visual Studio 2013 and Update 1 or above.

Now, lets see how to create ONE ASP.NET project.

It is again the standard template as usual you see when you create new project from Visual Studio.

Lets see the step by step process to create the One ASP.NET project.

First thing is, if you don’t have .NET framework 4.5.1 and visual studio 2013 with minimum update 1 then install that.

Once you install the above Open Visual Studio 2013 and go to File—> New—>Project

image

Select Visual C# and then select the .NET framework 4.5 or 4.5.1.and then select the ASP.NET Web Application. As soon as you click on “ASP.NET Web Application” template you may see the description of this template in the right pane as using this you can create ASP.NET web forms, MVC etc, type of applications.

image 

Click OK to create the project and start your application as per your requirement.

I hope now you understood what is One ASP.NET and how to create One ASP.NET project using Visual Studio 2013.

Thanks a lot for reading my article. Keep visiting my blog!

Tuesday, March 10, 2015

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format. - WCF IIS Hosting error

“Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format” is an error which you get while hosting the WCF service in IIS.

Lets see the complete exception details first,

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.

image

Reason for this error:

You get this error normally when you try to host a WCF service developed in Windows 32 bit machine and you are trying to host this in a 64 bit machine.

Solution to this issue is a simple one, you just need to change the settings in IIS to enable 32 bit application hosting.

Lets see the step step by actions to change this settings.

Open IIS --> Press Start button + R and then type inetmgr.

Expand your server and then click on Application Pools

In the list of application pools select the application pool which is being used by your new WCF service. And then click on the “Advance Settings…”

image

In Advance Settings dialog change the Enable 32-Bit Applications settings from False to True and Click OK.

image

Now you browse your WCF service and see the result. I am sure your error would have disappeared.

Monday, March 9, 2015

Can we insert explicit values into IDENTITY column in MS SQL

This is one of my favorite interview question. I hope you also would have faced this question, if not then there is a high possibility that you may face it soon!
Answer to the question Can we insert explicit values into IDENTITY column is MS SQL is YES. You can insert values into the IDENTITY column as you require.

Lets start step by step.

First lets create a table for the demo purpose,
CREATE TABLE DemoIdentity
(
    Id int IDENTITY (1, 1) not null,
    Name varchar(50) not null,
    [Address] varchar (100) not null,
    Phone char (15) not null
)
 
Table is ready, now we will insert some values to the above table.
INSERT INTO [DemoIdentity] ([Name] ,[Address] ,[Phone]) VALUES ('Asheej','Bangalore','9916123456')
INSERT INTO [DemoIdentity] ([Name] ,[Address] ,[Phone]) VALUES ('David','Birmingham','7543789234')
INSERT INTO [DemoIdentity] ([Name] ,[Address] ,[Phone]) VALUES ('Cliff','Columbus','4081234567')

Above is the standard way to insert the values into the table which has IDENTITY column.
image
Now lets try to insert a value with identity column value,

 
INSERT INTO [DemoIdentity] ([ID], [Name] ,[Address] ,[Phone]) VALUES (4,'Johnson','Perth','61478976782')

If you execute above SQL statement you will get below error,
Msg 544, Level 16, State 1, Line 11
Cannot insert explicit value for identity column in table 'DemoIdentity' when IDENTITY_INSERT is set to OFF.

Yes, now we will see the property which MS SQL provides you to insert values in IDENTITY column.
In SQL we have the property named IDENTITY_INSERT. Whenever you wanted to insert values to an IDENTITY column we just need to enable the property IDENTITY_INSERT.
Lets enable this property and insert a value in above table.
Syntax for enabling the IDENTITY_INSERT is,
SET IDENTITY_INSERT [DemoIdentity] OFF

Now we will insert the value by executing the same above statement by specifying the IDENTITY column value and see the result.
 image
One important thing you have to remember is, in order to enable or disable the IDENTITY_INSERT  property you should be part of the sysadmin group.

Make sure you disable the IDENTITY_INSERT ON once you are done with the insert statement as this column is not intended to insert the values explicitly.
Syntax for disabling the IDENTITY_INSERT is,
SET IDENTITY_INSERT [DemoIdentity] ON
 
I hope now you understood the whole concept of the property IDENTITY_INSERT and how you can insert explicit values into an IDENTITY column.

Thursday, March 5, 2015

The requested content appears to be script and will not be served by the static file handler – WCF IIS Hosting error

This is one of the most confusing error you get while hosting WCF service in IIS. Solution is simple but the error description completely misleads you to think in all the direction.
Below is the exact error,

HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.

image

The reason for the error is when you host a WCF service which is developed in .NET Framework 4.0 or 4.5 then while deploying by default IIS select .NET Framework 2.0.

In order to resolve this issue go to IIS and change the .NET Framework to the version which was used to develop your WCF service.
The exact step would be,

Press Start button  + R  and then type inetmgr.

Expand your server and then click on Application Pools

In the list of application pools select the application pool which is being used by your new WCF service.

Here you would have already noticed the wrong framework associated with your WCF service.

Just double click on the WCF Service name and change the .NET Framework version.

image
Click OK to save the changes. Now you browse your WCF service all your issues with your WCF service hosting error would have resolved.

Sunday, March 1, 2015

Where to find log files for the ASP.NET web application hosted in Windows Azure?

If you are a developer then definitely one of the question haunting you once you deploy your web application in Windows Azure is where is the log file? How can I go through the default log files which we have in IIS or in any other web server.

In this article all your such query will be answered. Once you login to your windows Azure account and open the web application configuration section you will find the option to configure all the log files, but there is no options available there to download or to view the log files. You may find all below options under Configure Menu but not the option to view the log files.

image

Lets see the available options to view the log files.

There are two ways you can view the log files related to your web applications deployed in Windows Azure.

1. Kudu Console. If you are hearing this first time then you may read my earlier article “” Once you open KUDU console you just need to go to the Tools menu and then you will find an option “Diagnostic dump” By clicking on this item will download the whole log files dump in your local system. Once you have the dump then nothing more to write about what you have to do.

image

2. Using Visual Studio: This one is interesting as you will be seeing the log files from your Visual Studio itself. In order to view the log files first you need to connect your Visual Studio with your Windows Azure account. If you are not aware of this feature, I have already written an article for you “”.  

Once you connect to your Visual Studio to your Windows Azure account then Expand Azure—>Websites—>Now expand the website name which you wanted to view the log files.

image
As soon as you expand your website which you wanted to view the log files you might have noticed a folder named “Log Files” This is our target today.
 
Lets expand the files and see the subfolders inside Log Files.
 
One thing you have to remember is this folder structure under log files in totally depends on the logging mechanism you have enabled for your application.
 
If you have enabled all the available logging then you may find many folders for each logs.
 
For your information I have expanded few of my already deployed in applications in my Windows Azure account.
image
Try to pen each log files under each folder if you like to explore more about the log files.

I hope you are now clear about the available log files in Windows Azure and how you can download or view this log files for debugging the issues.

Thanks a ton for reading my article and I hope it will help in your application development.

As usual you are always welcome to give feed back to my articles which may help me to improve next time.