[英]Url.Content type method in class library code
我在類庫中有這個代碼:
string.Format("{0}://{1}", Current.Request.Url.Scheme, Current.Request.Url.Authority);
如果應用程序部署在根域而不是子域中,則此方法可以正常工作。
我想使上述內容適用於子域。 在剃刀代碼中,我可以使用:
Url.Content("~/")
對於類庫是否有相應的('獨立於Web的'C#代碼)?
這個小函數將獲取應用程序根文件夾,例如'/'
或'/sub-folder/'
:
string GetAppRootFolder()
{
var appRootFolder = HttpContext.Current.Request.ApplicationPath.ToLower();
if (!appRootFolder.EndsWith("/"))
{
appRootFolder += "/";
}
return appRootFolder;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.