图像显示在localhost中,但不显示在Web服务器上 [英] Image is displaying in localhost but not displaying on the web server
本文介绍了图像显示在localhost中,但不显示在Web服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在asp.net项目的Web服务上上传图像的路径是什么?
当项目在本地主机上运行但我将其托管在Web服务器上时,将显示该图像.未显示.
我正在给程序上传本地主机中的文件.
请帮助我,网站的路径应该是什么.
what is the path to upload a image on the web serve of my asp.net project ?
the image is shown when the project running in local host but when i hosted it on the web server.It is not showing.
I am giving the program to upload a file in local host.
Please help me what is the path should be for web site.
void sub(Object s, EventArgs e)
{
con.Open();
Int32 x = 0;string y = GetRandomString(x);
int y1=0;
string y2="Code";
string s1=t1.Text.Trim();
string m;
int r=0;
DataRow []rs;
rs=ds.Tables["joining"].Select("aname='" +s1+"'");
r=rs.Length;
if((File1.PostedFile!=null)&&(File1.PostedFile.ContentLength>0))
{
fn=System.IO.Path.GetFileName(File1.PostedFile.FileName);
//Image1.ImageUrl=fn;
fn=y+fn;
//Response.Write(fn);
//Response.Write("<br>");
SaveLocation=Server.MapPath("~/Kamna Group Website/"+fn);
photo=SaveLocation;
com=con.CreateCommand();
com.CommandText="Insert into joining(aname,fathname,dob,pob,add1,mob,city,state,pcode,panno,nominee,relation,photo,bank,branch,account,acctype,intby,codno,doi,agent,point,refno) values('" + t1.Text.Trim() + "','" + t2.Text.Trim() + "','" + t3.Text.Trim() + "','" + t4.Text.Trim() + "','" + texta1.Value + "','" + t7.Text.Trim() + "','" + t5.Text.Trim() + "','" + t6.Text.Trim() + "','" + t8.Text.Trim() + "','" + t11.Text.Trim() + "','" + t9.Text.Trim() + "','" + t10.Text.Trim() + "','" + photo + "','" + t12.Text.Trim() + "','" + t13.Text.Trim() + "','" + t14.Text.Trim() + "','" + d1.SelectedItem.Text + "','" + t15.Text.Trim() + "','" + t16.Text.Trim() + "','" + t17.Text.Trim() + "','" + y2 + "','" + y1.ToString() + "','" + y + "')";
try
{
File1.PostedFile.SaveAs(SaveLocation);
com.ExecuteNonQuery();
System.Web.UI.WebControls.Label lbl1=new System.Web.UI.WebControls.Label();
lbl1.ForeColor=System.Drawing.Color.Blue;
lbl1.BackColor=System.Drawing.Color.Yellow;
lbl1.Text="You have joined us.We will contect you soon!";
ph1.Controls.Add(lbl1);
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
else
{
Response.Write("Please a file to upload");
}
con.Close();
}
private string GetRandomString(int seed)
{ const string alphabet = "abcdefghijklmnopqrstuvwxyz";
Random rnd = new Random((seed + DateTime.Now.Millisecond));
string result = rnd.Next(1000000, 9999999).ToString();
string alphaChar = alphabet.Substring(rnd.Next(0, alphabet.Length - 1), 1);
int replacementIndex = rnd.Next(0, (result.Length - 1));
result = result.Remove(replacementIndex, 1).Insert(replacementIndex, alphaChar);
return result;
}
推荐答案
简单用作
检查粗线
simly use as
check bold lines
protected void btnSub_Click(object sender, EventArgs e)
{
try
{
string filename = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Uploadform\\" + filename.Trim()));
string path = "~\\Uploadform\\" + filename.Trim();
SqlConnection con = new SqlConnection(str);
cmd = new SqlCommand("Insert into Circular(date,ctype,title,type,url1) values('"+txtdate.Text+"','" + TextBox1.Text + "','" + txttitle.Text + "','" + txttype.Text + "','" + path + "')", con);
lblinfo.Text = " Uploaded Successfully ";
cmd.CommandType = CommandType.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
这篇关于图像显示在localhost中,但不显示在Web服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文