开发者

Is it necessary to move a private class within an .aspx page to AppCode folder as a new .cs file?

开发者 https://www.devze.com 2023-02-22 22:23 出处:网络
Imagine a class that will be used only for internal operations within a web-form or a user control. Is there any disadvantages from the compiler point of view to introduce a class in the 开发者_运维百

Imagine a class that will be used only for internal operations within a web-form or a user control.

Is there any disadvantages from the compiler point of view to introduce a class in the 开发者_运维百科AppCode separately than declaring it inside the .aspx or .ascx as a private class.


So long as the user control itself is not stored in the App_Code folder, there a no disadvantages to placing your classes in there, in fact, it's desired - that's what it is for.

I think the main reason for the placement of code files within the App_Code folder is simply down to a couple of factors:

  • A conventional containing folder to store code
  • Relevant permissions applied by default so that your code files aren't browsable (at least)

I'm sure there'll be more benefits which an expert can explain, but generally I would advise you extract such classes from the web site / application and house such code in a dedicated compiled class library anyway.


There is no disadvantage, if your code is independent of the aspx/ascx, it is better to create it under the AppCode folder as a separate file.
You might also want to consider creating a separate class project for placing all your reusable classes so that they can be shared between multiple web applications.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号