简体   繁体   English

带服务的asp.net Web应用程序

[英]asp.net web application with a service

I have a simple asp.net web application project. 我有一个简单的asp.net Web应用程序项目。 Which has an order.aspx page showing different items. 其中有一个order.aspx页面显示不同的项目。 I have managed to show those items by outputting in page_load event. 我设法通过在page_load事件中输出来显示那些项目。

Now I am using JQuery to load item details from the database and show when the user clicks on the items. 现在,我正在使用JQuery从数据库加载项目详细信息,并显示用户单击项目的时间。

This is the JQuery I am using 这是我正在使用的JQuery

$(".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. 目前,我正在考虑其页面加载事件上的Lookup.aspx页面将从请求对象接收ID,我查询db填充数据并通过响应对象将其发送回。 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). 我尚未设置此设置,因为我在考虑是否要创建一个单独的页面来执行此操作,那么我将不得不为其他类型的查询创建更多页面(我将有其他查询,例如检查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. 对于Web服务部分。 The best and easiest way to go is WEB API. 最好,最简单的方法是使用WEB API。 Just write a controller method and it becomes a web service which returns json or xml. 只需编写一个控制器方法,它就成为返回json或xml的Web服务。

Using Web API with ASP.NET Web Forms 将Web API与ASP.NET Web窗体一起使用

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. 因此,无论是通过ajax还是仅通过拥有url的人,都将并且必须能够访问该方法。

A way to tackle this , is to encrypt-decrypt your product ID's . 解决此问题的一种方法是对产品ID进行加密-解密。

Or use authentication on web api. 或在Web API上使用身份验证。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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