TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vinod Kumar
NA
3
2.8k
ASP.NET MVC File Upload
Feb 4 2018 1:28 AM
Hi,
i have one mcv website for add produt detail with image. when i try to upload image in my local system it is working fine but after uploaded to webserver it is not working. i hosted in globhost.
this is the error getting
Access to the path 'D:\INETPUB\VHOSTS\vinvisinfoco.com\hoylsurgicals.com\Shopimg\9.jpg' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path 'D:\INETPUB\VHOSTS\vinvisinfoco.com\hoylsurgicals.com\Shopimg\9.jpg' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via
, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
iam using this code
public
ActionResult Add_Product(FormCollection fr, Models.ItemMaster I, HttpPostedFileBase file)
{
TempData[
"count"
] = fr.Get(
"a1"
);
string
ItemName = fr.Get(2);
string
ItemCode = fr.Get(3);
string
ItemType = fr.Get(4);
string
Brand = fr.Get(5);
string
Description = fr.Get(6);
string
Catid = Request.Form[
"Category"
];
string
filename = Session[
"Pid"
].ToString();
string
extn = file.FileName.Substring(file.FileName.LastIndexOf(
'.'
));
filename = filename + extn;
if
(ModelState.IsValid)
{
if
(file ==
null
)
{
ModelState.AddModelError(
"File"
,
"Please Upload Your file"
);
}
else
if
(file.ContentLength > 0)
{
int
MaxContentLength = 1024 * 1024 * 4;
//Size = 4 MB
string
[] AllowedFileExtensions =
new
string
[] {
".jpg"
,
".png"
};
if
(!AllowedFileExtensions.Contains
(file.FileName.Substring(file.FileName.LastIndexOf(
'.'
))))
{
ModelState.AddModelError(
"File"
,
"Please file of type: "
+
string
.Join(
", "
, AllowedFileExtensions));
}
else
if
(file.ContentLength > MaxContentLength)
{
ModelState.AddModelError(
"File"
,
"Your file is too large, maximum allowed size is: "
+ MaxContentLength +
" MB"
);
}
else
{
var path = Path.Combine(Server.MapPath(
"~/Shopimg"
), filename);
file.SaveAs(path);
filename =
"/Shopimg/"
+ filename;
Hoylsurgicals.Models.ItemMaster Prdct =
new
Models.ItemMaster();
if
(ModelState.IsValid)
{
try
{
Prdct.Itemid = Session[
"Pid"
].ToString();
Prdct.ItemName = ItemName;
Prdct.ItemCode = ItemCode;
Prdct.ItemType = ItemType;
Prdct.Brand = Brand;
Prdct.Description = Description;
Prdct.Picture = filename;
Prdct.CategoryId = Catid;
//Prdct.remarks = "verified";
var db =
new
Hoylsurgicals.Models.Dbclass();
db.ItemMasters.Add(Prdct);
db.SaveChanges();
TempData[
"msg"
] =
"registration successfully"
;
return
RedirectToAction(
"Productdetail"
,
"Admin"
);
}
catch
(Exception e)
{
Response.Write(e);
}
ModelState.Clear();
ViewBag.Message =
"File uploaded successfully. File path : ~/Shopimg/"
+ filename;
}
}
}
}
return
RedirectToAction(
"Productdetail"
,
"Admin"
);
}
please help me to solve this problem
thanks
vinod kumar
Reply
Answers (
1
)
Error :Object reference not set to an instance of an object
Resource file(.resx) update and generate in website