Saturday, May 3, 2025

How to create webapi in website without MVC Namespace - My First Webapi

 >First you have to add three files in project 1)Global.asax 2) testApiController.cs by adding web api controller class in project(add new item) 3)WebApiConfig.cs file

> Add below code in these files

  Global.asax

void Application_Start(object sender, EventArgs e) 

    {

        // Code that runs on application startup

        YashWebsiteWebForm.WebApiConfig.Register(System.Web.Http.GlobalConfiguration.Configuration);

    }


WebApiConfig.cs

 public static class WebApiConfig

    {

      

        public static void Register(HttpConfiguration config)

        {

            

            config.Routes.MapHttpRoute(

                name: "DefaultApi",

                routeTemplate: "api/{controller}/{id}",    

                defaults: new { id = RouteParameter.Optional }

                );

        }

    }

Monday, April 28, 2025

Saturday, April 26, 2025

How to create unique key in SQL server management studio

 >First Open Visual Studio

>Right Click on table and click on Design

>Right Click on column name left side

>Click on Indexes/Key

>Select Unique key in 'Type' Filed


Note:- Sometime unique key option is not visible

Saturday, April 19, 2025

asp.net button pass value to url in grid view

    <asp:Button ID="Button1" runat="server"

            PostBackUrl='<%# Eval("Id","~/Employee/Update/{0}") %>'

            Text="Save" Width="75px" />

Friday, April 18, 2025

how to use webclient class uploadstring - For webapi, webservice, handler - For post and for get

webclient in asp.net 


for get

 string handlerUrl = String.Format(Request.Url.Scheme+"://" +Request.Url.Authority+"{0}","/api/values");

        string response = (new WebClient()).DownloadString(handlerUrl);


for post

   using (var client = new WebClient())

        {

            string handlerUrl = String.Format(Request.Url.Scheme + "://" + Request.Url.Authority + "{0}", "/api/values");

            client.Headers[HttpRequestHeader.ContentType] =  "application/x-www-form-urlencoded";

            var data = "=Short test...";

            string result = client.UploadString(handlerUrl, "POST", data);

            

            Response.Write(result);

        }


 https://www.aspsnippets.com/Articles/2149/Call-Consume-Web-API-using-WebClient-in-ASPNet-C/