简体   繁体   中英

asp.net web application with a service

I have a simple asp.net web application project. Which has an order.aspx page showing different items. I have managed to show those items by outputting in page_load event.

Now I am using JQuery to load item details from the database and show when the user clicks on the items.

This is the JQuery I am using

$(".item").click(function(){
    $.post("Lookup.asp",
    {
        Id: $(this).id 
    },
    function(data, status){
        alert("Data: " + data + "\nStatus: " + status);
    });
});

Now I want to know how and what is the best way to setup the backend part to provide the data. Currently I am thinking that Lookup.aspx page on its page load event will receive the id from request object, I query the db populate the data and send it back through the response object. I am not sure if this is the right way of doing it.

I have not set this yet, because I was thinking if we create a separate page to do this then I will have to create more pages for other type of queries (I will have different queries like checking for status of an item in db).

Another problem I was thinking with this approach will be that there will be pages which are just serving the data and we dont want to show them to the public. If someone will have the name of the pages they can access them which we dont want.

And I am using Entity Framework it that matters in anyway.

For the Web Service part. The best and easiest way to go is WEB API. Just write a controller method and it becomes a web service which returns json or xml.

Using Web API with ASP.NET Web Forms

Now about the second part is tricky. IF your users are not logged in then , the method has to be public in order for someone to have access . So either through ajax either from just having the url someone will and must be able to access the method.

A way to tackle this , is to encrypt-decrypt your product ID's .

Or use authentication on web api.

https://www.asp.net/web-api/overview/security/authentication-and-authorization-in-aspnet-web-api

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM