zoukankan      html  css  js  c++  java
  • ASP.NET部署前环境检测

    /// <summary>
            
    /// 检测IIS及版本号
            
    /// </summary>
            
    /// <returns></returns>
            public string GetIISVerstion()
            {

                RegistryKey key 
    = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\INetStp");
                
    if (key == null)
                    
    return string.Empty;
                
    else
                    
    return Convert.ToString(key.GetValue("MajorVersion")) + "." + Convert.ToString(key.GetValue("MinorVersion"));

            }

    From: http://www.cnblogs.com/wujy/archive/2011/10/07/2200813.html

    --------------------------------------------------------------------------------------------------

    asp.net 验证 服务器 文件夹 权限

    (1) DirectoryInfo dInfo = new DirectoryInfo(@"d:\演示");
    if(dInfo.GetDirectories().IsReadOnly==true)//只读
    (2)try catch 上传一个文件试试,抛出异常查看异常是不是因为只读。

    AddDirectorySecurity(DirectoryName, "IIS_IUSRS", FileSystemRights.ReadData, AccessControlType.Allow);
    RemoveDirectorySecurity(DirectoryName, @"域\用户名", FileSystemRights.ReadData, AccessControlType.Allow);
    // Adds an ACL entry on the specified directory for the specified account.
            public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
            {
                // Create a new DirectoryInfo object.
                DirectoryInfo dInfo = new DirectoryInfo(FileName);

                // Get a DirectorySecurity object that represents the
                // current security settings.
                DirectorySecurity dSecurity = dInfo.GetAccessControl();

                // Add the FileSystemAccessRule to the security settings.
                dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                                                                Rights,
                                                                ControlType));

                // Set the new access settings.
                dInfo.SetAccessControl(dSecurity);

            }

            // Removes an ACL entry on the specified directory for the specified account.
            public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
            {
                // Create a new DirectoryInfo object.
                DirectoryInfo dInfo = new DirectoryInfo(FileName);

                // Get a DirectorySecurity object that represents the
                // current security settings.
                DirectorySecurity dSecurity = dInfo.GetAccessControl();

                // Add the FileSystemAccessRule to the security settings.
                dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
                                                                Rights,
                                                                ControlType));

                // Set the new access settings.
                dInfo.SetAccessControl(dSecurity);

            }
  • 相关阅读:
    [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ
    [安卓] 13、安卓蓝牙定位(一)——如何周期性获得蓝牙节点信号强度?
    [stm32] NRF24L01+USART搞定有线和无线通信
    [安卓] 12、开源一个基于SurfaceView的飞行射击类小游戏
    [安卓] 11、串口蓝牙·将软硬结合进行到底
    [安卓] 10、悬浮窗与获取其他任务信息
    [安卓] 9、线程、VIEW、消息实现从TCP服务器获取数据动态加载显示
    [安卓] 8、VIEW和SURFACEVIEW游戏框架
    [安卓] 7、页面跳转和Intent简单用法
    Git常用命令记录
  • 原文地址:https://www.cnblogs.com/8090sns/p/2881063.html
Copyright © 2011-2022 走看看