server.MapPath(“")在我的网站plesk上对我不起作用? [英] server.MapPath("") does not work for me in my website on plesk ??!!

查看:53
本文介绍了server.MapPath(“")在我的网站plesk上对我不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在本地计算机上运行项目时,它可以正常工作,但是当我将我的网站上传到plesk时,它给了我这样的错误:

拒绝访问路径``C:\ inetpub \ vhosts \ hamshahrisalam.com \ httpdocs \ Web.sitemap''


我的代码是

When I run my project on the local machine it works fine but when I uploaded my website on plesk ,it gives me an error like this:

Access to the path ''C:\inetpub\vhosts\hamshahrisalam.com\httpdocs\Web.sitemap'' is denied


My code is

System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory +"Web.sitemap", string);



我该怎么办?
请帮助我.



What can I do?
Please help me.

推荐答案

在这种情况下,Server.MapPath() 不是主要问题.如我所见,您的代码正在尝试写入Web.sitemap文件,并且为了成功完成此操作,Asp.net辅助进程必须具有对该特定文件的写许可权(Asp.net所使用的用户帐户)流程运行).

在您的PC中,工作进程用户帐户可能具有对特定文件的写许可权,因此它可以正常工作.但是,在服务器上,工作进程可能没有必要的权限.因此,它在那里失败.

要解决此问题,您可以采用以下两种方法:

1.确保工作进程用户帐户对目标文件夹/文件具有必要的写权限.

2.或者,重写您的Asp.net应用程序以在对该特定文件夹/文件具有写许可权的另一个用户帐户下运行(这称为Impersonation ,通常通过在web.config中设置一个元素来完成.了解如何执行此操作.

希望您能够解决问题.
In this case, Server.MapPath() is not the main issue. As I can see, your code is trying to write to a Web.sitemap file and in order to complete this operation successfully, the Asp.net worker process must have write permission to that specific file (The user account under which the Asp.net process runs).

In your PC, the worker process user account might have write permission on the specific file, so, it''s working. But, on server, the worker process might not have the necessary permission. So, it is failing there.

To solve this issue, you have two ways to follow:

1. Make sure that the worker process user account has necessary write permission on the target folder/file.

2. Or, override your Asp.net application to run under a different user account who has write permission on that specific folder/file (This is called Impersonation and usually done by setting an element in web.config. You can google to learn how to do this.

Hopefully, you will be able to solve your problem.


我相信您正在使用共享托管服务器.通常,共享托管服务器不提供对文件和目录的IO访问权限.如果确实需要,则需要向托管服务提供商请求访问权限.

如果您可以张贴目标(为什么要写入站点地图文件...等),这样会更好,可以找到另一种方法:)
I believe you are using a shared hosting server. Usually the shared hosting servers doesn''t provide IO access to files and directories....If you really require then you need to ask the hosting provider for the access.

It will be better if you can post you r objective (why do you want to write to the sitemap file...etc) so that an alternative way can be found :)


这篇关于server.MapPath(“")在我的网站plesk上对我不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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