c#尝试写入或者读取受保护的内存_C# 尝试读取或写入受保护的内存。这通常指示其他内存已损坏 | 学步园...

本文介绍了在C#中使用advapi32.dll的LogonUser方法进行Windows验证时遇到的‘尝试读取或写入受保护的内存’错误。错误原因在于将非托管代码参数ByRef phToken转换为INT,而应为ref IntPtr。修复此问题后,可以正常执行代码。
摘要由CSDN通过智能技术生成

一般来说IIS的验证方式有好几种,比较常见的就是匿名验证,集成Windows验证等等。 但是集成Windows验证每次都会谈个对话框出来,很麻烦,特别是在使用代理的情况下。

于是想能不能用一种Form的方式实现Windows验证呢? 当然啦,想想而已,本来对WEB开发就不算熟, Windows方面的就更差了。

在网上搜索到了一种方式,利用 advapi32.dll的LogonUser方法是可以验证你输入的用户名密码是不是Windows的有效用户的。

代码如下 :

'include permissions namespace for security attributes

'include principal namespace for windowsidentity class

'include interopservices namespace for dllImports.

Imports System.Security.Principal

Imports System.Security.Permissions

Imports System.Runtime.InteropServices

'

Public Class LogInUser

_

Private Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal

lpszPassword As String, _    ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken  As Integer) As

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值