为什么我的 .NET 应用程序在从网络驱动器运行时会崩溃?

发布于 2024-07-07 03:09:56 字数 594 浏览 13 评论 0原文

我的 .NET 应用程序在从网络驱动器运行时失败,即使相同的可执行文件从本地硬盘驱动器运行得很好?

我尝试像这样检查“完全信任”:

try
{
    // Demand full trust permissions
    PermissionSet fullTrust = new PermissionSet( PermissionState.Unrestricted );
    fullTrust.Demand();

    // Perform normal application logic

}
catch( SecurityException )
{
    // Report that permissions were not full trust
    MessageBox.Show( "This application requires full-trust security permissions to execute." );
}

但是,这没有帮助,我的意思是应用程序启动并且永远不会输入 catch 块。 但是,调试版本显示抛出的异常是由 InheritanceDemand 引起的 SecurityException。 有任何想法吗?

My .NET application fails when run from a network drive even when the very same executable runs perfectly fine from a local hard drive?

I tried checking for "Full trust" like so:

try
{
    // Demand full trust permissions
    PermissionSet fullTrust = new PermissionSet( PermissionState.Unrestricted );
    fullTrust.Demand();

    // Perform normal application logic

}
catch( SecurityException )
{
    // Report that permissions were not full trust
    MessageBox.Show( "This application requires full-trust security permissions to execute." );
}

However, this isn't helping, by which I mean the application starts up and the catch block is never entered. However, a debug build shows that the exception thrown is a SecurityException caused by an InheritanceDemand. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

山色无中 2024-07-14 03:09:56

这确实与网络位置上的应用程序不如本地硬盘上的应用程序受信任有关(由于 .NET 框架的默认策略)。

如果我没记错的话,微软最终在 .NET 3.5 SP1 中纠正了这个烦恼(在很多开发人员抱怨之后)。

我用谷歌搜索了它:.NET Framework 3.5 SP1 允许从网络共享启动托管代码!

It indeed has to do with the fact the apps on a network location are less trusted then on your local hdd (due to the default policy of the .NET framework).

If I'm not mistaken Microsoft finally corrected this annoyance in .NET 3.5 SP1 (after a lot of developers complaining).

I google'd it: .NET Framework 3.5 SP1 Allows managed code to be launched from a network share!

染火枫林 2024-07-14 03:09:56

您是否尝试过使用CasPol 完全信任共享

冷清清 2024-07-14 03:09:56

您可能已经完成了此操作,但您可以使用 CasPol.exe 为指定的网络共享启用 FullTrust。

例如,

cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
CasPol.exe -m -ag 1.2 -url file:///N:/your/network/path/* FullTrust

更多信息此处

You may have already done this, but you can use CasPol.exe to enable FullTrust for a specified network share.

For example

cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
CasPol.exe -m -ag 1.2 -url file:///N:/your/network/path/* FullTrust

More info here.

笑看君怀她人 2024-07-14 03:09:56

如果是 .NET 2.0 或更高版本,ClickOnce 的创建是为了真正帮助完成此部署工作。 我只使用它部署到网络共享。

If this is .NET 2.0 or greater, ClickOnce was created to really help with this deployment stuff. I only deploy to network shares using that.

所有深爱都是秘密 2024-07-14 03:09:56

这是微软在 .net 框架中内置的安全性。 这是一种阻止恶意软件以完全权限在本地运行的方法,因此您无法在代码中以编程方式更改此设置。

您需要做的是增加特定程序集的信任。 您可以在 .NET Framework 配置(控制面板 -> 管理工具)中执行此操作,并且必须在每台计算机上完成。

与任何安全措施一样,这是一件令人痛苦的事情,但会帮助世界减少感染等......

This is security built in by microsoft into the .net framework. It's a way of stopping malware to be run locally with full priviliges, so you cannot change this programmatically in the code.

What you need to do is increase the trust of specific assemblies. You do this in the .NET Framework Configuration (Control Panel->Administrative Tools), and has to be done on each computer.

As with any security measures, it's a pain-in-the-ass, but will help the world to be less infected etc...

心凉 2024-07-14 03:09:56

我所要做的就是将文件标记为只读(可能不相关),并将除完全控制之外的所有权限授予经过身份验证的用户。 在我这样做之前,当我为域用户设置仅网络共享时,我遇到了这个问题。

我发现了这个解决方法,因为管理员共享 (\server\C$) 和我自己的 PC 共享都没有这个问题。

编辑:应用程序面向 .NET 3.5,此处没有 SP1(版本 3.5.7283)

All I had to do was mark the files Read Only (possibly unrelated) and give all permissions except Full Control to Authenticated Users. I was encountering this issue before I did that, when I had the network share only setup for Domain Users.

I discovered this workaround because neither the admin shares (\server\C$) nor my own PC's shares had this problem.

Edit: App is targeting .NET 3.5, no SP1 here (version 3.5.7283)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文