简体   繁体   English

Javascript中包含的C#代码是否仍需要编译?

[英]Does C# code contained in Javascript still need to be compiled?

We have a web application built with C# and ASP.NET. 我们有一个使用C#和ASP.NET构建的Web应用程序。 I have to reference a few .NET session variables in my JavaScript code, so I use the following line to do so: 我必须在我的JavaScript代码中引用一些.NET会话变量,因此我使用下面的代码行:

var layoutID = '<%=Server.UrlEncode(string.Format("{0}", Session["layout_id"]))%>';

This works just fine. 这样很好。 The web application is built and published to our web server. Web应用程序已构建并发布到我们的Web服务器。 If I want to make a change, a .NET change would require me to compile the changes and publish it to the web server again. 如果要进行更改,.NET更改将要求我编译更改并将其重新发布到Web服务器。 If it's a JavaScript change, I can simply edit the js in the .ASPX page and the fix is immediately picked up...no compiling needed. 如果是JavaScript更改,我只需在.ASPX页面中编辑js,即可立即获得此修复程序...无需编译。

My question - what if I make a change to this inline C# code contained in JavaScript? 我的问题-如果我更改JavaScript中包含的此内联C#代码怎么办? Say, for example, I meant to access Session["layoutid"] without the underscore. 举例来说,我打算不带下划线访问Session [“ layoutid”]。 Could I just edit the .ASPX page on the web server, or will this require compiling just as if it were in a .CS file? 我可以只在Web服务器上编辑.ASPX页面,还是需要像在.CS文件中一样进行编译? I'm guessing since it's C#, I will still need to compile for the change to be picked up. 我猜是因为它是C#,所以我仍然需要编译以获取更改。 And yes I could just try it and see for myself, but I was hoping someone could give a little insight into what goes on behind the scenes with this inline c# code. 是的,我可以尝试一下,自己看看,但是我希望有人可以使用此内联c#代码对幕后发生的事情有所了解。 And while we're on the topic, is the technique I'm using to access .NET sessions variables in JavaScript the most efficient way to do it? 并且,当我们讨论主题时,我用来访问JavaScript中的.NET会话变量的技术是最有效的方法吗? Bonus question - what is this technique called? 奖励问题-这种技术叫什么? I tried searching for an answer but I wasn't sure what to search for other than "in-line c# code JavaScript". 我尝试搜索答案,但是除了“嵌入式C#代码JavaScript”之外,我不确定要搜索什么。

Thanks! 谢谢!

No, changes to ASPX/CSHTML files don't require re-compilation. 否,对ASPX / CSHTML文件的更改不需要重新编译。

Note: whether it is good idea to jump on production server and change random code bypassing source control/testing is question to discuss and answer by your team. 注意:跳至生产服务器并更改绕过源代码控制/测试的随机代码是否是一个好主意,这是您的团队讨论和回答的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM