簡體   English   中英

字符串未被識別為有效的DateTime

[英]String was not recognized as a valid DateTime

我的代碼是.......

  string PName = Request.QueryString["ProductName"] as string;
  string myDate = Request.QueryString["period"];

 string sql = "select FileName from tblProduct Where ProductName=" + PName;



    DateTime dt1 = Convert.ToDateTime(myDate);
    DateTime dt2 = DateTime.Now;
    TimeSpan variable = dt2 - dt1;
    if (variable.TotalMinutes > 5)
    {
        //Response.Write("Download time is expired now");
        lblmsg.Visible = true;
        lblmsg.Text = "Download time is expired now";
    }
    else
    {
        //string url1 = " http://www.shreehans.co.in/files/" + PName +"";
        //Response .Redirect ()
        lblmsg.Visible = true;
        lblmsg.Text = "U can Still Download";
    }

而且我的URl帶有querystring參數...

mail.Body + = string.Format(“ http://www.abc.co.in/Download.aspx?period=” + DateTime.Now +“&ProductName =” + productName +“ \\”>演示下載“);

如果在url(查詢字符串)中包含日期,則應將其編碼為Server.UrlEncode(DateTime.Now)

此外:

  1. 構造URI時,您缺少\\"
  2. 您的SQL代碼容易受到SQL注入攻擊。

這樣可以解決您的問題

mail.Body += 
   string.Format("http://www.abc.co.in/Download.aspx?period=" + 
   DateTime.Now.ToString("dd-MMM-yyyy") + 
   "&ProductName=" + productName + "\">Demo Download"); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM