Tag: ASP.NET
Building a ASP.NET Web API in Visual Studio 2015
This blog post will explain on how to create a Simple ASP.NET Web API using Microsoft Visual Studio 2015 and return an expose a List (Eg: List<Students>) over HTTP. This includes creating action methods and using them for get all students and get a particular student by id. How to create a Web API in Visual Studio 2015 and return a List over HTTP? Follow…
Asp.net GridView example using C#
Below is a sample code snippet for Asp.net GridView example using C#. The code snippet shows how to populate the GridView with a List of Employees. Asp.net GridView example using C# ASP.NET WebForms <asp:GridView ID=”GridView1″ runat=”server”> </asp:GridView> C# protected void Page_Load(object sender, EventArgs e) { List<Employee> employees = new List<Employee>(); employees.Add(new Employee { Name = “Test1”, Designtaion = “Software Engineer” }); employees.Add(new Employee { Name…
How to enable Tracing for a specific page in ASP.NET ?
In ASP.NET Web forms , you can enable the tracing for a specific page by adding the trace attribute to the Page element in the aspx page. How to enable Tracing for a specific page in ASP.NET ?
Server.MapPath with usage of . , .. , ~ and / Characters in ASP.NET
When using Server.MapPath in ASP.NET, the developers can specify the characters as shown below. var path1 = Server.MapPath(“.”)var path2 = Server.MapPath(“..”)var path3 = Server.MapPath(“~”)var path4 = Server.MapPath(“/”) What is the difference between the above methods ? Assume that the website is installed in the path D:\WebApplications\Abundantcode and the root of the IIS is C:\Inetpub\wwwroot and assume that the current page is http://abundantcode.com/popularposts The path1 will…
How to set default value for Html.TextBoxFor in ASP.NET MVC ?
You can set the default value for the Html.TextBoxFor extension controls in ASP.NET MVC by specifying the Value property as shown below. How to set default value for Html.TextBoxFor in ASP.NET MVC ?
How to read a key from the Web.Config file in ASP.NET app using C# ?
If you want to read the values based on the key from the web.config file in your ASP.NET application using C# , you can use the WebConfigurationManager to do it. How to read a key from the Web.Config file in ASP.NET app using C# ? Assume that the configuration file contains the below values If you want to read the value of the key (“UserName”)…
How to Add Web API to existing ASP.NET Web Forms Project ?
In one of the previous posts , we saw how to add the WebAPI to the existing ASP.NET MVC project. Well , the process of adding the ASP.NET Web API to the existing ASP.NET Web Forms project is still the same. You can easily do that by installing it from NuGet. Open the Package Console Manager in Visual Studio 2015 and run the following command….
Could not load file or assembly … An attempt was made to load a program with an incorrect format (System.BadImageFormatException)
There are times when you might get the following error when running the application from Visual Studio or opening your application page in the browser. Could not load file or assembly … An attempt was made to load a program with an incorrect format (System.BadImageFormatException) I received this error recently when trying to deploy the application in the IIS and accessing the page from the…
Posting Data to a URL using WebClient in C#
Below is a sample code snippet demonstrating the usage of the WebClient to post data to the server in C#. How to Post data to a URL using WebClient in C# ?
What is the Default Session State in ASP.NET if it is not configured in Web.config?
What is the Default Session State in ASP.NET if it is not configured in Web.config file? By default, the session state will be InProc in ASP.NET if it is not configured in the Web.Config file.
How to return Json instead of XML in ASP.NET Web API ?
When you make a call to the ASP.NET Web API action method and notice this in Google Chrome browser , you would see that by default the data would be displayed in the XML format as shown in the screenshot. How to return Json instead of XML in ASP.NET Web API ? You can easily change this behavior by adding the following code in the…
How to read a connection string from web.config file in ASP.NET ?
Assume that you have a connectionstring configured in the web.config file of your ASP.NET application and you wish to read it using C# within your application. How to read a connection string from web.config file in ASP.NET ? You can easily do that using the ConfigurationManager class defined in the System.Configuration namespace. 1. Ensure that the System.Configuration assembly is referenced in your project. 2. Add…