我是一名新程序员,试图理解别人的代码。该程序的目的是使用书签将 MySQL 数据放入 word 文件模板中。AR 和 ICN 是两种类型的报告,因此它们都有自己的模板。代码最初只包含 AR,我现在添加了 ICN。控制台应用程序运行良好,网页出现问题。我不明白为什么if (int.TryParse(ticketId, out currentTicket))
我的代码中FALSE
会生成 default.aspx 。
试图在浏览器中查看此代码
using System;
using System.Web;
using TicketExtractionLibrary;
namespace TicketExtractionWeb
{
public partial class GetAR : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ticketId = Request.QueryString["TicketId"];
int currentTicket;
string applicationPath = Request.PhysicalApplicationPath;
ARExtractionController ARController = new ARExtractionController();
string arTemplateLocation = HttpContext.Current.Server.MapPath("~/AR.dot");
string mappingLocation = HttpContext.Current.Server.MapPath("~/ARmapping.xml");
if (int.TryParse(ticketId, out currentTicket))
{
ARController.Extract(currentTicket, applicationPath + "LastTickets", arTemplateLocation, mappingLocation);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/msword";
Response.AddHeader("content-transfer-encoding", "binary");
Response.AddHeader("content-disposition", "attachment;filename=AR" + ticketId + ".docx");
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1251);
string path = Server.MapPath(@"\LastTickets\AR" + ticketId + ".docx");
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.WriteFile(path);
Response.End();
}
else
{
Response.Redirect("Default.aspx");
}
}
}
}