Access to the path "c:\inetpub\wwwroot\weblog\Entries\Entry.xml" is denied!
filepath=""c:\inetpub\wwwroot\weblog\Entries\Entry.xml"FileStream file = new FileStream(filePath, FileMode.Open);
访问被拒。。该怎么解决
winxp pro系统
其他程序也没有打开entry.xml
到底是什么原因被拒呢?
--------------------编程问答-------------------- Entry.xml,看下安全性,又无权限访问 --------------------编程问答-------------------- 没有权限访问 --------------------编程问答-------------------- window xp pro 也有权限设置吗?
--------------------编程问答-------------------- IUSR_已经是admin权限,还需要做其他的设置吗? --------------------编程问答-------------------- 如果是调试时候失败,把ASP.NET Machine Accout添上 --------------------编程问答-------------------- 什么开发模式?
winform还是b/s ?
winform因该不会出现这样的问题
B/s的话,默认是以network service用户身份访问的(win2000系统为aspnet).
需要给你要访问的文件/文件夹 加上该用户的写入权限 --------------------编程问答-------------------- 在计算机管理里面给ASPNET帐户administrator权限也运行调试不过去呀
“如果是调试时候失败,把ASP.NET Machine Accout添上”这个难道是添写在另外的地方吗?
是B/S模式,因为是xp pro系统,没有文件权限的设置,而且ASPNET隶属于administrator,还是失败了 --------------------编程问答-------------------- 难道是路径的原因?
浏览器默认不让访问本地文件
你把c:\inetpub\wwwroot\weblog\Entries\Entry.xml
改成Server.MapPath("Entries/Entry.xml")试验下。 --------------------编程问答-------------------- 这个本来就是用Server.MapPath()取得的路径,只是为了发帖才改成那样的,调试不过去还是。 --------------------编程问答-------------------- 按字面denied看,应该是用户或用户所属的组 的权限中 有“拒绝”,拒绝>一切。找找吧。
完全是猜测。 --------------------编程问答-------------------- 能不能多贴些代码阿? --------------------编程问答-------------------- //-------------------------default.aspx.cs-------------------
public partial class _Default : System.Web.UI.Page
{
public static String EntryFilePath;
protected void Page_Load(object sender, EventArgs e)
{
int year = DateTime.Now.Year;
if (year == 2000)
{
this.labelCopyRight.Text = "CopyRight reserved " + year;
}
else {
this.labelCopyRight.Text = "CopyRight reserved 2000-" + year;
}
this.LabelServerPath.Text = Server.MapPath("");
if (!Page.IsPostBack) {
EntryFilePath =Server.MapPath("Entries/Entry.xml");
Entry pageEntry = Global.LoadEntry(EntryFilePath);
this.LabelEntryTitle.Text = pageEntry.Title;
this.LabelEntryDetails.Text = pageEntry.Details;
}
}
}
//-----------------------------App_Code/global.cs------------
public class Global
{
public Global()
{
//
// TODO: Add constructor logic here
//
}
public static Entry LoadEntry(String FileName) {
String filePath = FileName;
FileStream file = new FileStream(filePath, FileMode.Open);
XmlSerializer xmler = new XmlSerializer(typeof(Entry));
Entry newEntry = (Entry)xmler.Deserialize(file);
file.Close();
return newEntry;
}
}
//----------------------------App_Code/Entry.cs----------------
public class Entry
{
public Entry()
{
//
// TODO: Add constructor logic here
//
}
private DateTime _timestamp;
private String _title;
private String _details;
[XmlIgnore()]
public DateTime Timestamp {
get {
return _timestamp;
}
set {
this._timestamp = value;
}
}
public String Title {
get {
return _title;
}
set {
this._title = value;
}
}
public String Details {
get {
return _details;
}
set {
this._details = value;
}
}
}
这些就是主要的程序了,问题在哪里?
靶子诶~先谢谢你 --------------------编程问答-------------------- see:
http://support.microsoft.com/kb/823379 --------------------编程问答-------------------- 还是那个样,没有变化。
-----------------------------------------------------------------------------------
Server Error in '/weblog' Application.
Access to the path 'c:\inetpub\wwwroot\weblog\Entries\Entry.xml' 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 'c:\inetpub\wwwroot\weblog\Entries\Entry.xml' 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 27: public static Entry LoadEntry(String FileName) {
Line 28: String filePath = FileName;
Line 29: FileStream file = new FileStream(filePath, FileMode.Open);
Line 30: XmlSerializer xmler = new XmlSerializer(typeof(Entry));
Line 31: Entry newEntry = (Entry)xmler.Deserialize(file);
Source File: c:\Inetpub\wwwroot\weblog\App_Code\Global.cs Line: 29
Stack Trace:
[UnauthorizedAccessException: Access to the path 'c:\inetpub\wwwroot\weblog\Entries\Entry.xml' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +2014419
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998
System.IO.FileStream..ctor(String path, FileMode mode) +65
Global.LoadEntry(String FileName) in c:\Inetpub\wwwroot\weblog\App_Code\Global.cs:29
_Default.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\weblog\Default.aspx.cs:29
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
--------------------编程问答-------------------- 哎。~回家调去,看看到底是不是公司机器问题 --------------------编程问答-------------------- 没权限访问,建议不要放在c盘,换个非系统盘,应该可以解决问题 --------------------编程问答-------------------- --------------------编程问答-------------------- 更改该文件夹的读写权限
补充:.NET技术 , ASP.NET