[巨额悬赏]ASP.Net底层开发问题,调用DLL,IIS6高手入

xunyuetian 2008-03-21 03:36:47
在IIS6下使用ASP.Net[DllImport(" 调用非托管加密狗的dll,然后IIS6停止响应,
程序在IIS5下无错,执行正常,在Windows2003+VS2005下调试无错,执行正常,但是在IIS6下就出错了,症状为IIS无响应

排除加密狗DLL内部接口问题,调用代码问题,并设置IIS6服务为IIS5模式,启用了父路径,启用IIS和桌面交互的服务

IIS6

示例调用代码:
public class DllInvoke
{
//引用系统方法来取得dll路径
[DllImport("kernel32.dll")]
private extern static IntPtr LoadLibrary(String path);
[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr lib, String funcName);
[DllImport("kernel32.dll")]
private extern static bool FreeLibrary(IntPtr lib);
[DllImport("user32.dll", EntryPoint = "MessageBox")]
public static extern int MessageBox(int hWnd, String strMessage, String strCaption, uint uiType);

private IntPtr hLib;
public DllInvoke(String DLLPath)
{
this.hLib = LoadLibrary(DLLPath);
}
~DllInvoke()
{
FreeLibrary(this.hLib);
}
//将要执行的函数转换为委托
public Delegate Invoke(String APIName, Type t)
{
IntPtr api = GetProcAddress(this.hLib, APIName);
return (Delegate)Marshal.GetDelegateForFunctionPointer(api, t);
}
}
--------------------
调用
DllInvoke dll = new DllInvoke(Server.MapPath(@"~/Bin/XXX.dll"));
按地址载入调用dll
XXX_GetNetState GetNetState = (XXX_GetNetState)dll.Invoke("XXX_GetNetState", typeof(XXX_GetNetState));
转换为委托方法
int status = GetNetState();
下面是传递参数例子:
...全文
273 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
w48948398 2010-12-23
  • 打赏
  • 举报
回复
高人出现了
xunyuetian 2008-03-25
  • 打赏
  • 举报
回复
问题终于解决了!使用身份模拟就可以了
public class IdentityAnalogue
{
//模拟指定用户时使用的常量定义
public const int LOGON32_LOGON_INTERACTIVE = 2;
/**/
///
///
///
public const int LOGON32_PROVIDER_DEFAULT = 0;
/**/
///
///
///
WindowsImpersonationContext impersonationContext;
//win32api引用
/**/
/// mmary>
///
///
///
///
///
///
///
///
///
[DllImport("advapi32.dll")]
public static extern int LogonUserA(string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
/**/
///
///
///
///
///
///
///
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken(IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);
/**/
///
///
///
///
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
/**/
///
///
///
///
///
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
/**/
///
///
///
public IdentityAnalogue()
{
}


//模拟指定的用户身份

/// <summary>
/// 身份模拟
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="domain">域</param>
/// <param name="password">密码</param>
/// <returns></returns>
public bool ImpersonateValidUser(string userName, string domain, string password)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (RevertToSelf())
{
if (LogonUserA(userName, domain, password, 2, 0, ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
{
CloseHandle(token);
CloseHandle(tokenDuplicate);
return true;
}
}
}
}
if (token != IntPtr.Zero)
CloseHandle(token);
if (tokenDuplicate != IntPtr.Zero)
CloseHandle(tokenDuplicate);
return false;
}

/// <summary>
/// 取消模拟
/// </summary>
public void UndoImpersonation()
{
impersonationContext.Undo();
}
}
dxy7093948 2008-03-24
  • 打赏
  • 举报
回复
你的程序是用1.1版本做的还是2.0的呢
rczjp 2008-03-24
  • 打赏
  • 举报
回复
mark
IIS本身的问题,或者是安装的问题
xunyuetian 2008-03-24
  • 打赏
  • 举报
回复
没人回答啊
xunyuetian 2008-03-22
  • 打赏
  • 举报
回复
没人遇到过这个问题么?
dubinwq 2008-03-21
  • 打赏
  • 举报
回复
幫樓主頂下
xunyuetian 2008-03-21
  • 打赏
  • 举报
回复
继续顶上去啊
shenjiaxiong 2008-03-21
  • 打赏
  • 举报
回复
友情顶下
xunyuetian 2008-03-21
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 youngerch 的回复:]
我认为是iis访问权限的原因
[/Quote]
目录为fat32目录 访问权限为Everyone仍出错
xunyuetian 2008-03-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lihongdian 的回复:]
你看一看调用非托管代码的程序式例吧,如果说IIS5可以运行就把IIS6设置成IIS5的模式吧.
再不行就调用COM互操作.
[/Quote]
已经改成IIS5模式还是错误。。。。。
youngerch 2008-03-21
  • 打赏
  • 举报
回复
我认为是iis访问权限的原因
youngerch 2008-03-21
  • 打赏
  • 举报
回复
UP
lihongdian 2008-03-21
  • 打赏
  • 举报
回复
你看一看调用非托管代码的程序式例吧,如果说IIS5可以运行就把IIS6设置成IIS5的模式吧.
再不行就调用COM互操作.
xunyuetian 2008-03-21
  • 打赏
  • 举报
回复
此程序调试模式下完全无错

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧