MVC数据对其他客户端可见

时间:2018-10-19 09:49:04

标签: c# asp.net model-view-controller web-applications controller

我对MVC的经验很少,因此我在学习过程中会遇到一些绊脚石。

我已经开始开发MVC Web应用程序,并且刚刚完成了一个表格,该表格调用Web服务以获取地址列表,并在每个地址中的select中填充选项。

这很好,但是我已经将其部署到测试服务器,并且在运行站点时可以运行,但是,如果我的另一个客户端的同事转到该页面,它将显示我运行的数据列表。该站点的每个呼叫都应该是个人的,因此不确定为什么其他人可以看到此数据吗?

查看(index.cshtml)

namespace AddressLookupSite.Controllers
{
public class AssistedController : Controller
{
    string postcode = "";
    string street = "";
    //model is the list of addresses to be returned to the user
    private static AddressList model = new AddressList();

    // GET: Assisted
    public ActionResult Index()
    {
        //this may need to be index,models.
        return View(model);
    }

    public ActionResult GetAddresses(string postcode)
    {
        if (postcode == null || postcode == "")
        {
            return RedirectToAction("/Index/");
        }
        //call Addresslookup web service
        AddressLookupWeb ew = new AddressLookupWeb();
        //extract address values from the XML returned from web service
        XmlNode xml = ew.GetAddress(", , , , " + postcode);

        foreach (XmlElement addressInfo in xml)
        {
            foreach (XmlElement teset in addressInfo["Addresses"])
            {
                //add each address item found to the list
                model.listone.Add(new AddressResults { FullAddress = teset["fulladdress"].InnerText });
            }
        }

        //return the list and model back to the index view
        return View("Index", model);


    }
}

模型(地址结果)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AddressLookupSite.Models
{
public class AddressResults
{
    public string FullAddress { get; set; }
}
}

模型(地址结果)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AddressLookupSite.Models
{
public class AddressList
{
    public List<AddressResults> listone = new List<AddressResults>();
}
}

视图非常标准,可以访问模型,将模型的内容输出到select中,它还使用一些JavaScript来执行一些基本代码。

问题绝对是服务器端的,它不应该允许其他用户截获该表单,尤其是因为该表单以后将包含个人数据。这让我想,如果我正处于填写表单的过程中,而其他人打开了该页面,那么当这种情况不应该发生时,它将为他们提供来自控制器的数据。

任何建议都值得赞赏,正如我所说,我是新来的,以前只是在开发内部应用程序以运行流程等。

1 个答案:

答案 0 :(得分:0)

您将结果模型定义为static并内联分配:

//model is the list of addresses to be returned to the user
private static AddressList model = new AddressList();

这意味着将只有一个此类的实例。这似乎是每个人获得相同结果的原因。

删除静态对象或在将使用该实例的方法中构造实例。要么给每个呼叫者自己的副本。