在服务器端使用Fileupload控件 [英] using Fileupload control on server side

查看:72
本文介绍了在服务器端使用Fileupload控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

am使用文件上载控件进行图像上载并将文件上载在localhost中正常工作,但是将我的应用程序托管在服务器上之后,它并没有收到错误提示



拒绝访问路径``\\ fs8-n01 \ stor11wc2dfw1 \ 450429 \ 592629 \ www.4i-solutions.com \ web \ content \ images \ DSCN1668(1).JPG''.

说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息.

异常详细信息:System.UnauthorizedAccessException:拒绝访问路径"\\ fs8-n01 \ stor11wc2dfw1 \ 450429 \ 592629 \ www.4i-solutions.com \ web \ content \ images \ DSCN1668(1).JPG".

没有授权ASP.NET访问请求的资源.考虑将资源的访问权限授予ASP.NET请求标识. ASP.NET具有一个基本进程标识(在IIS 5上通常为{MACHINE} \ ASPNET或在IIS 6上通常为Network Service),如果应用程序无法模拟,则可以使用该标识.如果应用程序正在通过< identity impersonate ="true">进行模拟,则该身份将是匿名用户(通常为IUSR_MACHINENAME)或已认证的请求用户.

要授予ASP.NET对文件的访问权限,请在资源管理器中右键单击该文件,选择属性",然后选择安全性"选项卡.单击添加"以添加适当的用户或组.突出显示ASP.NET帐户,然后选中所需访问权限的框.

源错误:


第57行:
第58行:字符串文件=〜/images/" + fup.FileName;
第59行:fup.SaveAs(Server.MapPath(file));
第60行:
第61行:SqlCommand cmd1 =新的SqlCommand(插入推荐值(""+ txtName.Text +",""+ file +",""+ txtContent.Text +"''), con);

和我的代码是一样的

am using the file upload control for image uploading and file uploading its working good in localhost but after am hosting my application on server its didn''t wrk am getting the fallowing error



Access to the path ''\\fs8-n01\stor11wc2dfw1\450429\592629\www.4i-solutions.com\web\content\images\DSCN1668 (1).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 ''\\fs8-n01\stor11wc2dfw1\450429\592629\www.4i-solutions.com\web\content\images\DSCN1668 (1).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) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true">, 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 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:


Line 57:
Line 58: string file = "~/images/" + fup.FileName;
Line 59: fup.SaveAs(Server.MapPath(file));
Line 60:
Line 61: SqlCommand cmd1 = new SqlCommand("insert into testimonials values(''" + txtName.Text + "'',''" + file + "'',''"+txtContent.Text+"'')", con);

AND MY CODE IS AS FALLOWS

protected void Button1_Click(object sender, EventArgs e)
   {
       string file = "";
       con.Open();
       file = "~/images/" + fup.FileName;
       fup.SaveAs(Server.MapPath(file));

       SqlCommand cmd1 = new SqlCommand("insert into testimonials values('" + txtName.Text  + "','" + file + "','"+txtContent.Text+"')", con);

       int i = cmd1.ExecuteNonQuery();
       con.Close();

       if (i > 0)
       {
           Response.Write("uploaded");
       }

   }



请帮忙...



PLZ HELP FOR THIS...

推荐答案

此处存在逻辑错误.当您尝试通过查询发送所有路径名时,特殊字符会阻止此操作.
这里有两个主要解决方案
1.通过参数发送值,
2.仅发送文件名(不包括路径),并且在需要此文件时,再次声明路径并仅获取文件名(当然,请再次使用参数)

希望有帮助.
There is a logical error here. When you try to send all the path name by query, the special characters blocks this.
There are two main solution here
1. Send your values via parameters,
2. Send only the file name (do not include the path) and when you need this file, declare the path again and get only file name (and of course use parametres again)

Hope that helps.


出现权限问题.

1.在目录->中添加 IIS_IUSRS .右键单击属性->您在哪里的安全性
要上传文件.
2.授予对修改的访问权限.
its a permission issue.

1. Add IIS_IUSRS in directory --> right click properties --> security where you
want to upload files.
2. Give access of Modify to it.


向服务器上的images文件夹提供所有权限.

右键单击图像文件夹,然后单击属性

现在,单击"Web共享"选项卡弹出窗口将打开以提供权限,然后提供所有权限,然后单击确定"

然后检查可能会解决您的问题.
provide all the permission to the images folder on server.

right click on the images folder and click on properties

now click on web sharing tab popup window will open for permission provide all the permission then click OK

then check may be your problem will be solved.


这篇关于在服务器端使用Fileupload控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆