在Global Trust中从Global.asax重定向 [英] Redirecting from Global.asax in Medium Trust
问题描述
我正在尝试在Global.asax中的Application_Error处理程序中进行重定向.一点都不幻想.
I am attempting to do a redirect in the Application_Error handler in Global.asax. Nothing fancy at all.
private void Application_Error(object sender, EventArgs e)
{
// ...snip...
Server.Transfer(somePath, false);
// ...snip...
}
这在完全信任"下很好用,但是我需要让它在中等信任"下起作用.我在此处使用的代码需要在共享托管环境中正常运行(很遗憾,我无法控制此要求).
This works great under Full trust, but I need to get it to work under Medium trust. The code I'm working on here needs to function properly in a shared hosting environment (Unfortunately, I have no control over this requirement).
但是,当我在开发环境(XP Pro/IIS 5.1)中按以下方式配置站点以进行测试时:
However, when I configure the site as follows in our dev environment (XP Pro / IIS 5.1) for testing purposes:
<system.web>
<trust level="Medium"/>
</system.web>
它失败并出现以下错误:
It fails with the following error:
Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.**
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Web.HttpWorkerRequest.SendResponseFromMemory(IntPtr data, Int32 length)
at System.Web.HttpWorkerRequest.SendResponseFromMemory(IntPtr data, Int32 length, Boolean isBufferFromUnmanagedPool)
at System.Web.HttpResponseUnmanagedBufferElement.
System.Web.IHttpResponseElement.Send(HttpWorkerRequest wr)
at System.Web.HttpWriter.Send(HttpWorkerRequest wr)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpResponse.Flush()
at System.Web.HttpResponse.End()
at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
其他一些注意事项:
- 无论是从Global.asax还是从HttpModule,都会发生这种情况.
- 这也发生在Response.Redirect(somePath)中.
赞赏您可以提供的任何见解.我已经为此用Google $ a $折扣了,没什么好高兴的.
Appreciate any insight you can provide. I have Googled my a$$ off over this, and no joy.
谢谢!
推荐答案
我遇到了与您相同的问题.
I had the same problem like you.
我用过:
Response.Redirect("~/ErrorRedirectPage.aspx",false);
它工作正常.
这篇关于在Global Trust中从Global.asax重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!