C#登录远程windows系统示例

public class Global : System.Web.HttpApplication
    
{
        
protected void Application_Start(object sender, EventArgs e)
        
{
            System.Runtime.Remoting.RemotingConfiguration.Configure(Server.MapPath(HttpContext.Current.Request.ApplicationPath 
+ "/web.config"), false);

            Application[
"helper"= new Helper();

            
string password = "";

                IntPtr accessToken 
= new IntPtr(0);
                SimpleCrypto.PasswordDecrypt(ConfigurationManager.AppSettings[
"UPLOAD_PASSWD"], out password);
                
if (NetworkSecurity.LogonAndGetToken(ConfigurationManager.AppSettings["UPLOAD_SITE"],
                    ConfigurationManager.AppSettings[
"UPLOAD_USER"], password,
                    ConfigurationManager.AppSettings[
"UPLOAD_NETWORK_LogonType"], ConfigurationManager.AppSettings["UPLOAD_NETWORK_LogonProvider"],
                    
ref accessToken) == false)
                
{
                    
throw new Exception("Logon Failed");
                }

                password 
= "";
                Application.Add(
"AccessToken", accessToken);

                HttpContext.Current.User 
= new WindowsPrincipal(new WindowsIdentity((IntPtr)Application["AccessToken"]));
                (HttpContext.Current.User.Identity 
as WindowsIdentity).Impersonate();
                FileStream fs 
= new FileStream(ConfigurationManager.AppSettings["UPLOADSGFT"], FileMode.Open, FileAccess.Read);
                StreamReader st 
= new StreamReader(fs, System.Text.Encoding.Default);
                
string word;
                Dictionary
<stringstring> postFilter = new Dictionary<stringstring>();
                
while ((word = st.ReadLine()) != null)
                
{
                    
if (!word.Trim().StartsWith("//"&& !postFilter.ContainsKey(word.Trim().ToLower()))
                        postFilter.Add(word.Trim().ToLower(), 
string.Empty);
                }

                st.Close();
                Application.Add(
"FilterText", postFilter);

        }


        
protected void Application_End(object sender, EventArgs e)
        
{
            NetworkSecurity.CloseToken((IntPtr)Application[
"AccessToken"]);
            Application.Clear();
        }

    }
 
阅读更多
上一篇C#登录远程windows系统
下一篇FormsAuthenticationTicket基于forms的验证
想对作者说点什么? 我来说一句

Remote远程调用方法示例

2008年06月10日 43KB 下载

没有更多推荐了,返回首页

关闭
关闭