【发布时间】:2018-01-15 16:38:59
【问题描述】:
使用:Visual Studio 2015,C#,在 Surface Pro 3 上,运行 Windows 10 Pro 技能等级:新手
我创建了一个个人网站并将其部署到 Azure 托管。在我的一个 Web 表单中,我从 DropDownList 控件(书籍、文章、专着等)中选择一种参考类型。然后,我将几条引文数据输入到 TextBox 控件中。然后我按下一个按钮。所有 TextBox 数据都写入 XML 文件。另外,后面的 .aspx.cs 代码中还有一系列 if-then 语句。根据 DropDownList SelectedItem,只有一个 if-then 语句为真。因此,例如,如果 SelectedItem 是“专着”,则 TextBoxes 中的文本将附加到字符串中,并根据脚注中引用专着的格式进行格式化。
.cs 摘录...
string referenceType = ddlType.SelectedItem.Text;
...
if (referenceType == "Monograph")
{
longCite = "<span style='font-variant:small-caps'>" + author + "</span>";
longCite = longCite + "<span style='font-variant:small-caps'>" + fullTitle + "</span>";
pin1 = longCite;
pin2 = " (";
if (txtPublisher.Text.Trim() != "") { pin2 = pin2 + txtPublisher.Text.Trim(); }
pin2 = pin2 + ", " + fullDate + ")" + country + URL;
longCite = pin1 + pin2;
}
上面代码中构建的字符串被写入 XML 文件的子节点(摘录如下)...
XDocument xRef = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("ref",
new XElement("id", txtID.Text),
new XElement("type",
new XAttribute("id", ddlType.SelectedValue.ToString()),
ddlType.SelectedItem.Text),
new XElement("author",
new XAttribute("alpha", txtAuthorAlpha.Text),
txtAuthor.Text),
new XElement("title", txtTitle.Text),
new XElement("titlePrefix", txtTitlePrefix.Text),
new XElement("subtitle", txtSubtitle.Text),
new XElement("subDivider", txtSubDivider.Text),
new XElement("language",
new XAttribute("id", ddlLanguage.SelectedValue.ToString()),
new XAttribute("display", ddlLanguage.SelectedItem.Text),
fullLang),
new XElement("country",
new XAttribute("id", ddlCountry.SelectedValue.ToString()),
new XAttribute("name", ddlCountry.SelectedItem.ToString())
),
new XElement("countries", txtCountries.Text.Trim()),
new XElement("publisher", txtPublisher.Text),
new XElement("date",
new XAttribute("day", ddlDay.SelectedValue.ToString()),
new XAttribute("month", ddlMonth.SelectedValue.ToString()),
new XAttribute("year", txtYear.Text),
fullDate),
new XElement("longURL", txtLongURL.Text),
new XElement("shortURL", txtShortURL.Text),
new XElement("pin1", pin1),
new XElement("pin2", pin2),
new XElement("shortCite", shortCite),
new XElement("longCite", longCite),
new XElement("notes", txtNotes.Text)
)
);
xRef.Save(Server.MapPath("~/App_Data/references/" + txtID.Text + ".xml"));
当我在开发环境中构建和测试它时,这非常有效。当我在 Azure 上尝试它时,它不起作用。 XML 文件已正确创建,所有节点都已填写,除了在 if-then 语句中构建的 pin1、pin2 和 longCite 节点。
我已经重新发布了整个网站。我已经重新发布了特定的网络表单和背后的代码。我已删除 XML 文件并在本地服务器上的 Web 表单中重新创建它们,然后在 Azure 服务器上再次创建它们。两个相同的网站。两种不同的结果。在我的本地机器上运行它时,我在 if-then 语句中设置了断点,它会命中断点。我在 Azure 服务器上运行时查看了 Web 表单,以确保选择 DropDownList 上的正确项目并正确拼写
<select name="ctl00$MainContent$ddlType" id="MainContent_ddlType">
...
<option selected="selected" value="monograph">Monograph</option>
有什么想法吗?是否存在我应该解决的已知 Azure 和/或 Visual Studio 错误?
【问题讨论】:
-
为什么在Azure运行的时候不设置断点并在那里检查?为什么不使用 Serilog 或 NLog 等将日志记录添加到您的应用程序?
-
我不知道我能做到这一点。是否有在线教程显示如何?我是新手。
-
是的,有教程。对于 Azure 断点,如果你有 VS 2017 就很简单。你为什么不使用最新的?转到查看 > 云资源管理器。确保您已登录到您的 Azure 帐户(单击小人物图标)。确保您选择订阅。然后深入到应用服务,右键单击并附加调试器。您可能需要部署 Debug 版本,而不是 Release 版本。
标签: c# asp.net xml azure visual-studio-2015