【发布时间】:2019-03-24 04:49:19
【问题描述】:
我对 MVC 的经验很少,所以我边走边学,遇到了一些绊脚石。
我已经开始开发 MVC Web 应用程序,并且刚刚完成了一个表单,该表单调用 Web 服务以获取地址列表并使用每个地址填充选择中的选项。
这很好用,但是我已将其部署到测试服务器,并且当我运行该站点时它可以工作,但是如果我的另一个客户端的同事访问该页面,它会显示我运行的数据列表。对网站的每次调用都应该是单独的,所以不确定为什么其他人可以看到这些数据?
查看(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来做一些基本的代码。
问题肯定是服务器端的,它不应该让其他用户能够拦截表单,特别是因为表单稍后会包含个人数据。这让我想到,如果我正在填写表格并且其他人打开了页面,那么当它不应该发生时,这会给他们来自控制器的数据。
非常感谢任何建议,因为我说我是新手,以前只开发内部应用程序来运行流程等。
【问题讨论】:
标签: c# asp.net model-view-controller web-applications controller