简体   繁体   English

ASP.NET(C#)的Define()(PHP)替代

[英]Define() (PHP) Alternative for ASP.NET (C#)

Is there an alternative to define("BASE_PATH", "http://localhost"); 是否有define("BASE_PATH", "http://localhost");的替代方法define("BASE_PATH", "http://localhost"); for PHP in ASP.NET C#? 在ASP.NET C#中使用PHP?

I've been searching online for hours, yet most results give me 'definitions' of asp.net, or php, or alternative (lol?). 我已经在网上搜索了几个小时,但是大多数结果都给我提供了asp.net,php或替代方法的“定义”(大声笑?)。

Thank you 谢谢

Use a static or a constant of appropriate visibility to the use in question. 对相关用途使用可见性的静态或常数。

For a base path, Request.ApplicationPath may be more useful than something hard-coded. 对于基本路径, Request.ApplicationPath可能比硬编码的东西有用。

这做同样的事情:

const string BASE_PATH = "http://localhost";

define is a constant assignment in PHP . definePHP的常量分配。 Since ASP.NET is object-oriented language you assingn constants something like 由于ASP.NET是面向对象的语言,因此您需要设置常量,例如

class YourCSharpClass{
    const string ConstName = <value>;
}

But I think you assign some special meaning to those BASE_PATH variable. 但是我认为您为这些BASE_PATH变量分配了一些特殊含义。 Are you using Windows.Forms or ASP.NET MVC? 您正在使用Windows.Forms还是ASP.NET MVC?

I've never seen this before but looking it up it seems like this definition is only used for prepanding aa url? 我以前从未见过,但查找它似乎仅用于预定义网址? Do you need to do this can't you make everything relative? 您需要这样做吗?

Alterantively you could probably use the AppSettings. 或者,您可能会使用AppSettings。

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

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