最近很多小伙伴都在问SQLServer:如何检查是否启用了CLR?和如何检查sql服务是否启动这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展android–phonegap:如何
最近很多小伙伴都在问SQL Server:如何检查是否启用了CLR?和如何检查sql服务是否启动这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展android – phonegap:如何检查是否启用了gps、Android:检查是否启用了Google设置位置、asp.net-mvc – 如何检查是否为浏览器启用了cookie、c# – 检查是否启用了UserPrincipal等相关知识,下面开始了哦!
本文目录一览:- SQL Server:如何检查是否启用了CLR?(如何检查sql服务是否启动)
- android – phonegap:如何检查是否启用了gps
- Android:检查是否启用了Google设置位置
- asp.net-mvc – 如何检查是否为浏览器启用了cookie
- c# – 检查是否启用了UserPrincipal
SQL Server:如何检查是否启用了CLR?(如何检查sql服务是否启动)
SQL Server 2008-检查clr是否启用的简便方法是什么?
答案1
小编典典SELECT * FROM sys.configurationsWHERE name = ''clr enabled''
android – phonegap:如何检查是否启用了gps
如何使用phonegap获取GPS状态?
我使用了以下代码,但如果关闭GPS,我不会收到任何警报消息.相反没有任何反应
<!DOCTYPE html> <html> <head> <title>Device Properties Example</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8"> // Wait for device API libraries to load // document.addEventListener("deviceready",onDeviceReady,false); // device APIs are available // function onDeviceReady() { var test= navigator.geolocation.getCurrentPosition(onSuccess,onError); } // onSuccess Geolocation // function onSuccess(position) { var element = document.getElementById('geolocation'); element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' + 'Longitude: ' + position.coords.longitude + '<br />' + 'Altitude: ' + position.coords.altitude + '<br />' + 'Accuracy: ' + position.coords.accuracy + '<br />' + 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' + 'heading: ' + position.coords.heading + '<br />' + 'Speed: ' + position.coords.speed + '<br />' + 'Timestamp: ' + position.timestamp + '<br />'; } // onError Callback receives a PositionError object // function onError(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } </script> </head> <body> <p id="geolocation"> Finding geolocation...</p> </body> </html>
解决方法
isGpsLocationEnabled()
启用了GPS:
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){ console.log("GPS location is " + (enabled ? "enabled" : "disabled")); },function(error){ console.error("The following error occurred: "+error); });
如果结果是GPS已关闭,您可以将用户切换到位置设置页面以手动启用GPS:
cordova.plugins.diagnostic.switchToLocationSettings();
或者,此外,您可以使用cordova-plugin-request-location-accuracy直接从应用程序内请求高精度定位模式(即GPS).这将显示原生确认对话框,如果用户同意,将自动启用GPS:
function onRequestSuccess(success){ console.log("Successfully requested accuracy: "+success.message); } function onRequestFailure(error){ console.error("Accuracy request Failed: error code="+error.code+"; error message="+error.message); if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_disAGREED){ if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){ cordova.plugins.diagnostic.switchToLocationSettings(); } } } cordova.plugins.locationAccuracy.request(onRequestSuccess,onRequestFailure,cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
Android:检查是否启用了Google设置位置
如何编程检查Android应用程序中是否启用了谷歌设置位置?
http://www.cnet.com/how-to/explaining-the-google-settings-icon-on-your-android-device/
解决方法
LocationManager lm = null; boolean gps_enabled,network_enabled; if(lm==null) lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); try{ gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); }catch(Exception ex){} try{ network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); }catch(Exception ex){} if(!gps_enabled && !network_enabled){ dialog = new AlertDialog.Builder(context); dialog.setMessage(context.getResources().getString(R.string.gps_network_not_enabled)); dialog.setPositiveButton(context.getResources().getString(R.string.open_location_settings),new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface,int paramInt) { // Todo Auto-generated method stub Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); context.startActivity(myIntent); //get gps } }); dialog.setNegativeButton(context.getString(R.string.Cancel),int paramInt) { // Todo Auto-generated method stub } }); dialog.show(); }
ACTION_LOCATION_SOURCE_SETTINGS显示用户,允许配置当前位置源的设置.
asp.net-mvc – 如何检查是否为浏览器启用了cookie
解决方法
/// <summary> /// Ensures that cookies are enabled. /// </summary> /// <exception cref="CookiesNotEnabledException" /> [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method,AllowMultiple = true,Inherited = true)] public class EnsureCookiesAttribute : Filterattribute,IAuthorizationFilter { private readonly string _cookieName; private readonly bool _specificCookie; /// <summary> /// The name of the cookie to use to ensure cookies are enabled. /// </summary> [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage","CA2211:NonConstantFieldsShouldNotBeVisible",Justification = "Field is public so that the default value may be modified.")] public static string DefaultCookieName = "SupportsCookies"; public const string CookieCheck = "cookieCheck"; /// <summary> /// Checks to make sure cookies are generally enabled. /// </summary> public EnsureCookiesAttribute() : this(null) { } /// <summary> /// Checks to make sure a cookie with the given name exists /// </summary> /// <param name="cookieName">The name of the cookie</param> public EnsureCookiesAttribute(string cookieName) { if (String.IsNullOrEmpty(cookieName)) { cookieName = DefaultCookieName; } else { _specificCookie = true; } QueryString = CookieCheck; _cookieName = cookieName; } /// <summary> /// The name of the cookie to check for. /// </summary> public string CookieName { get { return _cookieName; } } /// <summary> /// The querystring parameter to use to see if a test cookie has been set. /// </summary> public string QueryString { get; set; } protected static CookiesNotEnabledException CreatebrowserException() { return new CookiesNotEnabledException("Your browser does not support cookies."); } protected static CookiesNotEnabledException CreateNotEnabledException() { return new CookiesNotEnabledException("You do not have cookies enabled."); } #region Implementation of IAuthorizationFilter /// <summary> /// Called when authorization is required. /// </summary> /// <param name="filterContext">The filter context.</param> [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design","CA1031:DoNotCatchGeneralExceptionTypes",Justification = "Should swallow exceptions if a cookie can't be set. This is the purpose of the filter.")] public void OnAuthorization(AuthorizationContext filterContext) { if (filterContext == null) throw new ArgumentNullException("filterContext"); var request = filterContext.HttpContext.Request; var response = filterContext.HttpContext.Response; if (!request.browser.Cookies) throw CreatebrowserException(); string currentUrl = request.RawUrl; var noCookie = (request.Cookies[CookieName] == null); if (!_specificCookie && noCookie && request.QueryString[QueryString] == null) { try { // make it expire a long time from Now,that way there's no need for redirects in the future if it already exists var c = new HttpCookie(CookieName,"true") {Expires = DateTime.Today.AddYears(50)}; response.Cookies.Add(c); currentUrl = currentUrl + (currentUrl.Contains('?') ? "&" : "?") + QueryString + "=true"; filterContext.Result = new RedirectResult(currentUrl); return; } catch { } } if (noCookie) throw CreateNotEnabledException(); } #endregion } /// <summary> /// Thrown when cookies are not supported. /// </summary> [Serializable] public class CookiesNotEnabledException : HttpException { public CookiesNotEnabledException() { } protected CookiesNotEnabledException(SerializationInfo info,StreamingContext context) : base(info,context) { } public CookiesNotEnabledException(string message) : base(message) { } public CookiesNotEnabledException(string message,Exception innerException) : base(message,innerException) { } }
您可以使用它来确保启用cookie
[EnsureCookies] [HandleError(ExceptionType = typeof(CookiesNotEnabledException),View="NoCookies")] public ActionResult logon(....) ...
或确保为某个操作设置了特定的Cookie
[EnsureCookies("MyCookie")] [HandleError(ExceptionType = typeof(CookiesNotEnabledException),View="Some cookie not set view"] public ActionResult ActionThatNeedsMyCookie()....
我不确定你为什么需要那样做,但确实如此.希望它有所帮助.
c# – 检查是否启用了UserPrincipal
private bool IsUserEnabled(UserPrincipal userPrincipal) { bool isEnabled = true; if (userPrincipal.AccountExpirationDate != null) { // Check the expiration date is not passed. if (userPrincipal.AccountExpirationDate <= DateTime.Now) { Log.DebugFormat("User {0} account has expired on {1}",userPrincipal.displayName,userPrincipal.AccountExpirationDate.Value); isEnabled = false; } } if (userPrincipal.IsAccountLockedOut()) { isEnabled = false; Log.DebugFormat("User {0} account is locked out",userPrincipal.displayName); } if (userPrincipal.Enabled != null) { isEnabled = userPrincipal.Enabled.Value; Log.DebugFormat("User {0} account is Enabled is set to {1}",userPrincipal.Enabled.Value); } return isEnabled; }
由于userPrincipal.Enabled检查,大多数帐户似乎已禁用.
但是,如果我将其删除并仅依赖帐户到期日期和帐户锁定属性,那么我可能会错过使用Active Directory中的复选框禁用该帐户的人员,而无需设置帐户到期日期.
启用的所有帐户返回false实际上是可以登录到域的活动帐户.
如何检查帐户是否实际启用?
解决方法
我最初使用System.DirectoryServices.DirectorySearcher来搜索已禁用的用户. AD用户记录的状态(re:禁用,锁定,密码到期等)存储在UserAccountControl属性中.您可以将过滤器传递给DirectorySearcher,通过将UserAccountControl属性指定为过滤器的一部分来定位禁用帐户.
我从不喜欢这种方法,因为它等于使用魔术字符串和一些魔术数字来构建查询;例如,这是用于查找已禁用帐户的过滤器:
var searcher = new DirectorySearcher(dirEntry) { Filter = "(UserAccountControl:1.2.840.113556.1.4.803:=2)",PageSize = 50 };
当我切换到使用UserPrincipal时,我很高兴在类上看到这个非常好用的“Enabled”属性.至少在我意识到它没有返回DirectorySearcher过滤器返回的相同值之前.
不幸的是,我可以找到确定帐户是否实际启用的唯一可靠方法是深入挖掘底层的DirectoryEntry对象,并直接检查UserAccountControl属性,即:
var result = (DirectoryEntry)userPrincipal.GetUnderlyingObject(); var uac = (int)result.Properties("useraccountcontrol"); var isEnabled = !Convert.ToBoolean(uac & 2);
注 – UserAccountControl属性是“flags”枚举;可以在此处找到UserAccountControl属性的所有可能值:https://msdn.microsoft.com/en-us/library/aa772300(v=vs.85).aspx
我最终将上面的代码片段构建成一个小扩展方法;幸运的是,这项额外的工作来检索UserAccountControl属性并没有明显减慢我的AD查询速度.
我们今天的关于SQL Server:如何检查是否启用了CLR?和如何检查sql服务是否启动的分享已经告一段落,感谢您的关注,如果您想了解更多关于android – phonegap:如何检查是否启用了gps、Android:检查是否启用了Google设置位置、asp.net-mvc – 如何检查是否为浏览器启用了cookie、c# – 检查是否启用了UserPrincipal的相关信息,请在本站查询。
本文标签: