Last post Jul 25, 2016 07:39 AM by Yohann Lu
Jul 22, 2016 02:47 PM|tarun02|LINK
I am working on an asp.net webforms application.It is a medium scale
accounting application.It has 4 layers consisting of Common(for POCO/Models),DataAccess(DAL),Logic(BAL),Presentation Layer(All the webform pages) and ServerControls(controls for the grid).For most of
tasks i have been using web services.webservices in then calls the logic
from the business layer.And i call the web methods using ajax.It works fine.Now i wanted to use webapi and have tried a bit,did some tests for
GET and POST and it works just fine.I just wanted to know like how
should i restructure this whole project?I have like hundreds of aspx
pages.And i have used Session in this project for storing the user_id
and office_id of the logged in users.Like i read somewhere here that
sessions arent a good idea for webapi because that makes it stateful and
not stateless.Any other alternatives?Overall expert advice on using
WebApi with webforms.
Jul 25, 2016 03:17 AM|Yohann Lu|LINK
As far as I know, the ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET
I just wanted to know like how
should i restructure this whole project?
I suggest you can establish a separate Web API program and interact with your Web Application.
Getting Started with ASP.NET Web API 2 (C#):
You can call Web API use HttpWebRequest in your WebForm Application.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:9601/api/Values");//
request.Method = "Post";
request.KeepAlive = true;
request.ContentType = "appication/json";
//request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string myResponse = "";
using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
myResponse = sr.ReadToEnd();
You can also add a Web API controller in your Web Forms application.
Using Web API with ASP.NET Web Forms:
Jul 25, 2016 07:35 AM|tarun02|LINK
Thank you sir..i saw the tutorials..so my aspx button event now goes to the webapi sir?
Jul 25, 2016 07:39 AM|Yohann Lu|LINK
Yes, your aspx button event can make a call to Web API. You can make a test on your side.