Reputation: 433
I'm creating a page to upload images to the root and this is the following code
if (fileimage.HasFile)
{
string Extension = System.IO.Path.GetExtension(fileimage.FileName);
if (Extension.ToLower() != ".gif" && Extension.ToLower() != ".png" && Extension.ToLower() != ".jpg" && Extension.ToLower() != ".jpeg")
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Invalid image format ');", true);
}
else
{
int FileSize = fileimage.PostedFile.ContentLength;
if (FileSize > 1048576)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Maximum file size 1 mb ');", true);
}
else
{
string pathName = "img/" + Path.GetFileName(fileimage.PostedFile.FileName);
SqlConnection con = new SqlConnection("Data Source=drasatwebmarket.db.10125920.hostedresource.com; Initial Catalog=drasatwebmarket; User ID=Username; Password='Password';");
SqlCommand cmd = new SqlCommand("insert into imageupload(imagepath) values ('" + pathName + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
fileimage.SaveAs(Server.MapPath("~/webmaketing/img/" + fileimage.FileName));
Response.Write("<script language=javascript>alert('Image Uploaded Succssfuly')</script>");
}
}
}
else
{
Response.Write("<script language=javascript>alert('Please Select Image To Uploade')</script>");
}
When I try to upload an image it shows up a dialog requesting user name and a password as following.
Note: the IIS settings at the server is set to anonymous access
Upvotes: 0
Views: 1339
Reputation: 4866
This looks like GoDaddy so please try this in your web.config:
<system.web>
<trust level="Full" />
</system.web>
Also check this if that alone does not solve it.
<system.web>
<authentication mode="Windows" />
<authorization>
<allow users="?" />
<allow users="*" />
</authorization>
</system.web>
Another quick test is to set Everyone-Read under File Manager permissions.
Upvotes: 1