C# System.Security.SecurityException:请求主体权限失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8812926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 04:33:37  来源:igfitidea点击:

System.Security.SecurityException: Request for principal permission failed

c#asp.netiisweb-configlivedocx

提问by brady.vitrano

Can anyone help point me in the right direction of how I might be able to fix this error?

任何人都可以帮助我指出如何解决此错误的正确方向吗?

System.Web.Services.Protocols.SoapException: Server was unable to process request. 
     ---> System.Security.SecurityException: Request for principal permission failed.
at System.Security.Permissions.PrincipalPermission.ThrowSecurityException()
at System.Security.Permissions.PrincipalPermission.Demand()
at System.Security.PermissionSet.DemandNonCAS()
at LiveDocx.MailMerge.SetLocalTemplate(String template, String format)

I have installed this software that my company purchased from LiveDocx. So, I don't have ability to modify code or even read the code. I have installed everything according to their documentation and the site is confirmed to work. I can only change settings in IIS, folder permissions, and Web.config. Our server, their software.

我已经安装了我公司从 LiveDocx 购买的这个软件。所以,我没有能力修改代码甚至阅读代码。我已根据他们的文档安装了所有内容,并且该站点已确认可以正常工作。我只能更改 IIS、文件夹权限和 Web.config 中的设置。我们的服务器,他们的软件。

Now, I am having issue with staying logged into the webservice. Before you think it is the soap client, I have confirmed that it works by calling the vendor's servers.

现在,我在保持登录 Web 服务时遇到问题。在您认为它是soap 客户端之前,我已经通过调用供应商的服务器确认它可以工作。

Locally, I can successfully call the web service during login and it works fine. However, when I make a subsequent call, I get the Request for principal permission failed.

在本地,我可以在登录期间成功调用 Web 服务,并且工作正常。但是,当我进行后续调用时,我得到了Request for principal permission failed.

At the request of their technical support, I have added <trust level="Full" />to the web.config, but that didn't work. Now, they have stopped replying to our emails.

应他们技术支持的要求,我已将其添加<trust level="Full" />到 web.config,但这不起作用。现在,他们已停止回复我们的电子邮件。

I am not an ASP.NET developer, so my knowledge is limited on server settings. Can someone point me in the right direction why this error happens and a few places to look to resolve this issue?

我不是 ASP.NET 开发人员,所以我对服务器设置的了解有限。有人可以指出我为什么会发生此错误的正确方向以及解决此问题的几个地方吗?

采纳答案by brady.vitrano

I finally found a solution. This error about permissions is a bit misleading. After lots of trial and errors, I finally accepted the Application Pool user's permissions had nothing to do with this problem. Which lead me to investigate the web.configsettings and that is where I found the problem.

我终于找到了解决方案。这个关于权限的错误有点误导。经过多次尝试和错误,我终于接受了与此问题无关的应用程序池用户的权限。这导致我调查web.config设置,这就是我发现问题的地方。

The problem was that the supplied web.configfile was missing <authentication>tag and the required settings. This tag (from my understanding) is what enables cookies. I hope this helps others with this error even if not related to LiveDocx. Seems Request for principal permission failed.can be caused for various reasons which makes it a frustrating error.

问题是提供的web.config文件缺少<authentication>标签和所需的设置。这个标签(根据我的理解)是启用 cookie 的原因。我希望这可以帮助其他人解决此错误,即使与 LiveDocx 无关。似乎Request for principal permission failed.是由于各种原因造成的,这使它成为一个令人沮丧的错误。

This article was very helpful How To: Use Membership in ASP.NET 2.0

这篇文章非常有帮助How To: Use Membership in ASP.NET 2.0

回答by competent_tech

I would suspect the identity of the user that is executing the request, which is most likely the ASP.Net Application Pool user for the web site your IIS application is running in.

我会怀疑执行请求的用户的身份,这很可能是运行 IIS 应用程序的网站的 ASP.Net 应用程序池用户。

The easiest way to test this is to create a new application pool for your IIS application (unless there are no other apps in your current app pool), choose a different identity for the app pool (you could start with network service, but it may require a local user), then assign your app to that pool.

测试这个最简单的方法是为你的 IIS 应用程序创建一个新的应用程序池(除非你当前的应用程序池中没有其他应用程序),为应用程序池选择一个不同的身份(你可以从网络服务开始,但它可能需要本地用户),然后将您的应用分配到该池。

This should tell you if it's a permissions problem with the app pool identity.

这应该会告诉您应用程序池标识是否存在权限问题。

回答by mhenry1384

I ran into this because I had an application under a website configured to use the wrong cookie name.

我遇到了这个问题,因为我在网站下有一个应用程序配置为使用错误的 cookie 名称。

The web.config at my root web site looked like this

我的根网站上的 web.config 看起来像这样

<authentication mode="Forms">
  <forms name="AuthCookie" path="/"></forms>
</authentication>

and the application under it had a web.config under that looked like this

并且它下面的应用程序有一个 web.config 看起来像这样

<authentication mode="Forms">
  <forms name="WRONGCOOKIENAME" path="/"></forms>
</authentication>

The application had web form with a constructor that looked like this

该应用程序具有带有构造函数的 Web 表单,如下所示

[PrincipalPermissionAttribute(SecurityAction.Demand, Role = "Foo", Authenticated = true)]

So it required authentication but it didn't have it because the cookie name was wrong. Fixing the cookie name resolved the error.

所以它需要身份验证,但没有它,因为 cookie 名称是错误的。修复 cookie 名称解决了错误。

回答by Sofin S

I had a similar issue and I was using a forms application and keep on getting this issue. I was also using Principal permission and Security Action Demand.

我有一个类似的问题,我正在使用表单应用程序并继续遇到这个问题。我还使用了 Principal 权限和 Security Action Demand。

I tried all the web.config related settings and the final issue was with the application pool.

我尝试了所有与 web.config 相关的设置,最后一个问题是应用程序池。

If you are having the application migrated from WinXP to Win7 and other higher version you might see there is a Managed Pipeline which is by default pointing the website to Intergrated mode. I changed this to classic mode which has fixed the issue. Hopefully this would help the members who are trying to move the application from WinXp to Win7

如果您将应用程序从 WinXP 迁移到 Win7 和其他更高版本,您可能会看到有一个托管管道,默认情况下将网站指向集成模式。我将其更改为经典模式已解决该问题。希望这对尝试将应用程序从 WinXp 移动到 Win7 的成员有所帮助