一段c#程序中的问题,关于string contactId=new Guid().ToString()的问题
Default.aspx.cs文件代码:using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
string contactId = new Guid(Request.QueryString["id"]).ToString();
string pictureFilename = (Server.MapPath("/" + "productpictures"), contactId + ".jpg");
if (File.Exists(pictureFilename))
{
string pictureURL = "../" + "productpictures/GetPic.aspx?id=" + contactId + "&temp=" + Guid.NewGuid().ToString();
Image1.ImageUrl = pictureURL;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string contactId = new Guid(Request.QueryString["id"]).ToString();
if (FileUpload1.HasFile)
{
string pictureFilename = (Server.MapPath("/" + "productpictures"), contactId + ".jpg");
FileUpload1.SaveAs(pictureFilename);
string pictureURL = "../" + "productpictures/GetPic.aspx?id=" + contactId + "&temp=" + Guid.NewGuid().ToString();
Image1.ImageUrl = pictureURL;
}
}
}
GetPic.aspx.cs文件代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using
public partial class GetPic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string picid = Request.QueryString["id"];
string pictureFilename = (Server.MapPath("/productpictures"), picid + ".jpg");
Response.Clear();
Response.ClearHeaders();
Response.AppendHeader("content-type", "image/jpeg");
Response.WriteFile(pictureFilename);
Response.Flush();
Response.End();
}
}
问题是Default.aspx.cs中的string contactId = new Guid(Request.QueryString["id"]).ToString()不可以被替换成string contactId = Request.QueryString["id"];而GetPic.aspx.cs中用string picid = Request.QueryString["id"]就可以,这是为什么?我没看懂。
谁能给解释一下,谢谢