server_a和server_b是一个域里面的两台机器,操作系统为2003server,主程序部署在a上。
在域控制器中建立了一个用户domain\xxx,并在server_b的upload文件夹上加入这个域用户,赋予读写权限,并共享这个文件夹。
在server_a上的iis建立虚拟目录指向\\server_b\upload,连接的用户是域用户。
做完以上设置,通过浏览器可以正常访问到 upload目录中的内容。
我在程序中有一个上传文件的应用,现在想上传到upload目录中,用.net 2.0的uploadfile控件实现,但上传的时候提示:“ASP.NET 未被授权访问所请求的资源”
在网上查了很多资料之后,我在server_a的iis中站点属性>目录安全性>身份验证和访问控制>匿名用户>>加入domain\xxx,并在web.config中加入<identity impersonate="true">模拟登录,这样改掉以后,可以成功上传到upload目录中了,但在浏览器访问upload中的内容,出现500错误。其实我要求实现的功能很简单,几台机器在一个域里,iis有个虚拟目录指向网络共享目录,可以用asp.net上传和正常访问。

解决方案 »

  1.   

    这个是不同的,你在计算机可以访问另一台机器的共享文件夹,但是从网页打开,并不是windows身份登录,而是IIS来宾用户.
    方法:模仿windows身份登录:
    using   System; 
    using   System.Data; 
    using   System.Configuration; 
    using   System.Web; 
    using   System.Web.Security; 
    using   System.Web.UI; 
    using   System.Web.UI.WebControls; 
    using   System.Web.UI.WebControls.WebParts; 
    using   System.Web.UI.HtmlControls; 
    using   System.Security.Principal; 
    using   System.Runtime.InteropServices; ///   <summary > 
    ///   Summary   description   for   WindowsAuthentication 
    ///   </summary > 
    public   class   WindowsAuthentication 
    {         [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);         public   WindowsAuthentication() 
            { 
                    // 
                    //   TODO:   Add   constructor   logic   here 
                    // 
            }         public   static   void   CreateIdentity() 
            { 
                    //   The   Windows   NT   user   token. 
                    IntPtr   tokenHandle   =   new   IntPtr(0); 
                    const   int   LOGON32_PROVIDER_DEFAULT   =   0; 
                    const   int   LOGON32_LOGON_NETWORK_CLEARTEXT   =   2; 
                    tokenHandle   =   IntPtr.Zero; 
                  //账户信息,写在配置文件中 
                    String[]   tempAccount   =   ConfigurationManager.AppSettings["AspNetaccount"].ToString().Split(new   char[]   {   "; "   }); 
                    bool   returnValue   =   LogonUser(tempAccount[1],   tempAccount[0],   tempAccount[2], 
                              LOGON32_LOGON_NETWORK_CLEARTEXT,   LOGON32_PROVIDER_DEFAULT, 
                              ref   tokenHandle); 
                    if   (false   ==   returnValue) 
                    { 
                            int   ret   =   Marshal.GetLastWin32Error(); 
                            throw   new   Exception("LogonUser   failed   with   error   code:   "   +   ret); 
                    } 
                    WindowsIdentity   id   =   new   WindowsIdentity(tokenHandle); 
                    CloseHandle(tokenHandle); 
                    id.Impersonate(); 
            } 

      

  2.   

    在配置文件中记载一个本域内,有相应权限的账户信息 
    如: 
      <appSettings > 
            <add   key="PathOfMarketingAutoMailList"   value="\\server\Archive\Testautomails\"/ > 
            <add   key="AspNetaccount"   value="cadpro.com.cn;woodlee;0"/ > 
      //分别是:   域名   账户   密码 
        </appSettings > 
      

  3.   

    理由上面已经说了;我记得在以前看过在web.config里面可以模拟用户权限的,具体的没记住,帮不了你了