Performance works using runat = server to control html

I tried to do it and walked a bit, so maybe someone here can shed some light on this topic.

To reassign URLs in asp.net, I would like to declare all images and other resources in my application with the runat = "server" attribute in order to use the ~ / images server path syntax. Debugging at locahost is especially difficult when using relative paths (when using URL rewriting). I know that I can modify the host files to fix this problem a little, but this is not possible in terms of the volume of projects we are working on.

The declaration of html controls for the runat server usually adds to the viewstate to ensure data consistency, but this does not apply to images, or am I mistaken about this ...?

I also understand that there are more controls for the asp net runtime processing and processing, but is this really a serious performance leak ...?

Is there any serious overhead in declaring images this way, and if so, can someone explain exactly where the bulk of the performance will be produced.

Thanks in advance.

+3
source share
2 answers

Assuming you are requesting differences between:

1) <img runat="server" EnableViewState="false" src="~/images/img.png" />

and

2) <img src='<%= ResolveUrl ("~/images/img.png") %>' />

To build 1) the actual code generated (more or less):

System.Web.UI.HtmlControls.HtmlImage __ctrl;
__ctrl = new System.Web.UI.HtmlControls.HtmlImage();
this._bctrl_1 = __ctrl;
__ctrl.EnableViewState = false;
__ctrl.Src = "~/image.png";

__ctrl :

__parser.AddParsedSubObject(this._bctrl_1); // _bctrl_1 is __ctrl from above

(Init, Load...) , RenderControl HTML-, ResolveUrl() URL- , , Dispose() .

, 2), , - :

__ctrl.SetRenderMethodDelegate(new System.Web.UI.RenderMethod(this.__RenderTree));

, , <img> . __RenderTree , , :

__output.Write("\n<img src='");
__output.Write( ResolveUrl ("~/image.png") );
__output.Write("' />\n");

, , "" 1), 2). , , , . / img, -0,5 /+ 0,5 . .

+5

, viewstate marlarky. , , .

, HTML. "control", .

, , , .. . , , HTML, ASP.NET.

, runat = "server" . , , , .

, - , .

, , - "/". , /myprojectname/part URL-. .

0

Source: https://habr.com/ru/post/1722771/


All Articles