System.IO.Directory.CreateDirectory(@"\\youserver\web\123456"); 报错!!!!! 
未找到路径“\\youserver\web”的一部分。 
已经映射,已经登陆,操作系统可以建立,但我的程序为什么建立不了???c#是使用的什么身份??
使用System.IO.Directory.CreateDirectory建立UNC目录,应该怎么建立???要用模拟身份吗??
应该没这么麻烦吧?? 
请老大指点^^^^  

解决方案 »

  1.   

    如果已经登陆,那应该可以创建
    你的是不是ASP.NET程序?执行WEB程序的用户是ASPNET,默认没有IO权限,你得自己加
      

  2.   

    to: Sunmast(速马|Maybe I'm Amazed) ( )
    我的环境是 win2003+IIS6权限怎么加啊???  IIS6中好象不是ASPNET,好象是NETWORK SERVICE    不太懂,能说清楚点吗??
      

  3.   

    跟iis6无关。iis6是web server,aspnet是.net application的account,要让aspnet可以读写那个目录。
      

  4.   

    要让aspnet可以读写那个目录。
    对!
      

  5.   

    to:athossmth(athos) 哦 明白你的意思,本地可以,可操作局域网内的另一台PC还是不成
    System.IO.Directory.CreateDirectory(@"\\youserver\web\123456"); 报错!!!!! 
    未找到路径“\\youserver\web”的一部分。 
      

  6.   

    我想在A机器操作B机器,如果在B机器的相应目录将ASPNET帐户加入写的权限,但这个是B机器的ASPNET帐号,而c#程序在A机器里,用的是A机器里的ASPNET用户,我试了,还是不成^^  大家多帮忙啊
      

  7.   

    楼上大哥的意思是 要在B机器上加个WEBSERVICE  是吗?? 麻烦了点吧 如果用模拟: 我在网上找到了一段 ,
    http://www.cnblogs.com/dahuaidan410/archive/2004/10/27/57471.aspx但我不会使用啊,我是在局域网里操作
    public static void ImpersonateAndDo(string UserName, string PWD, ImpersonatedWork WhatToDo)
    这里面的参数应该怎么加????   B机器里的用户Administrator  PWD= 123456  机器名=book 总是抱错:  1326  87 ………………
      

  8.   

    看来只能用模拟身份了  ,但我不知道模拟的是本地用户还是另一台PC的用户????下面的代码模拟身份,但用法:
    WindowsImpersonationContext wic=CreateIdentity(
    username, domain,
    pwd ).Impersonate();
    总是报错 LogonUser failed with error code: " 132……     为什么???CODE:[DllImport("advapi32.dll", SetLastError=true)]
    private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
    [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
    private extern static bool CloseHandle(IntPtr handle);
    protected static WindowsIdentity CreateIdentity(string User, string Domain, string Password)
    {
    // The Windows NT user token.
    IntPtr tokenHandle = new IntPtr(0);
    const int LOGON32_PROVIDER_DEFAULT = 0;
    const int LOGON32_LOGON_NETWORK = 3;
    tokenHandle = IntPtr.Zero;
    // Call LogonUser to obtain a handle to an access token.
    bool returnValue = LogonUser(User, Domain, Password, 
    LOGON32_LOGON_NETWORK, 
    LOGON32_PROVIDER_DEFAULT, 
    ref tokenHandle);
    if (false == returnValue)
    {
    int ret = Marshal.GetLastWin32Error();
    throw new Exception("LogonUser failed with error code: " +  ret);

    //The WindowsIdentity class makes a new copy of the token.
    //It also handles calling CloseHandle for the copy.
    WindowsIdentity id = new WindowsIdentity(tokenHandle);
    CloseHandle(tokenHandle);
    return id;
    }用法:
    WindowsImpersonationContext wic=CreateIdentity(
    username, domain,
    pwd ).Impersonate();
    //做那些需要权限的操作wic.Undo();我们的思归大哥哪去了??????????????????????
      

  9.   

    haike(小虾米) ( ) 信誉:100 怎样才算是给一个用户分配了IO权限啊?????
      

  10.   

    B机在A机上建目录,先在A机上注册一用户,用这个用户名登陆不就得了不建用户的话哪不成黑客了。
      

  11.   

    to:koenemy(牵只蚂蚁蹓跶) ( ) 当然已经建立了,权限也分配了,而且也登陆了   而且也用操作系统(我的电脑)建立了,这都成,可程序怎么建立??建立不了啊
      

  12.   

    webservice is a better solution.
    the truth is that when different user visit your application,the io operation will regard them as different users ,not aspnet ,iis_anonymous or assigned computer account on the goal computer.
      

  13.   

    tajlolo(tajlolo) ( ) 信誉有帐户,有密码,这样建立应该不算黑客吧,,我觉得不太黑
      

  14.   

    to: wacle([Smile!]) ( ) 
    谢谢您可我要操作好多台服务器,不能每台都要做个Webservice吧我的环境: 一台管理平台电脑, 多台服务器, 要自动批量建立目录,用户.用户可以用WMI建立,但目录不知道怎么用WMI建立   帮忙