Why not use GDI+ from ASP.NET

不打扰是莪最后的温柔 提交于 2019-12-29 00:46:09

问题


I've been told that using GDI+ from ASP.NET is dangerous and undefined.

Is that because there is no guarantee of a Device Context? Can someone explain?

What are some of the alternatives?

Here is the MSDN source:

http://msdn.microsoft.com/en-us/library/system.drawing.aspx

Edit

Windows and ASP.NET service! So perhaps a normal ASP.NET application is ok? But why?

Edit

This is not an April Fools joke, please don't treat it as such.


回答1:


There are numerous articles on the subject and it is possible to call this code from .NET. You need to make sure that you are disposing any objects that you create, so making use of the C# using statement is important.

The reason that System.Drawing could be problematic is that it is closely bound with how Windows does it's drawing. You should isolate the code as much as possible. With Windows Vista and later Microsoft made some changes to the service architecture which prevented interactions between the desktop and Windows services. ASP.NET is technically a service if it is hosted in IIS (most common case) so this is why Microsoft added the note. Future versions of Windows and IIS may make it more difficult or impossible to use System.Drawing from ASP.NET application.

The challenge is that some people may have misused the technology on other projects and now these people are trying to influence your use of it. One way to deal with these concerns (invalid or not as the case may be) is to create some performance and reliability metrics. Then when you start using GDI+ demonstrate the impact of it's use. The impact should be acceptable in most cases, but this will depend on what you want to do with GDI+.




回答2:


There are scalability concerns around the creation of windows handles and resources that GDI+ uses in a web environment.

Placed ASP.NET GDI+ code in a singleton so that calls are serialised and dispose of objects correctly.

I have used this technique for dynamically created images without a hitch.



来源:https://stackoverflow.com/questions/2562699/why-not-use-gdi-from-asp-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!