我有一个奇怪的事情发生,我在 VS2012 中制作的 C# 应用程序在 IIS 下的我的电脑上运行得很好,但是当我把它放在服务器上时,会发生什么我正在记录错误,例如,
2013-07-02 10:08:44,572 [5] ERROR Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine [(null)] <(null)> - Could not render view
NVelocity.Exception.MethodInvocationException: Invocation of method 'theme_skin_url' in stellar.Services.themeService threw exception System.NullReferenceException : Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at stellar.Services.themeService.theme_skin_url(site site, String theme, String mode, String type) in d:\._GIT_\HIV PROJECT\stellar\Services\site_controlls\themeService.cs:line 292
at stellar.Services.themeService.theme_skin_url(String type) in d:\._GIT_\HIV PROJECT\stellar\Services\site_controlls\themeService.cs:line 280
--- End of inner exception stack trace ---
at NVelocity.Runtime.Parser.Node.ASTMethod.Execute(Object o, IInternalContextAdapter context)
at NVelocity.Runtime.Parser.Node.ASTReference.Execute(Object o, IInternalContextAdapter context)
at NVelocity.Runtime.Parser.Node.ASTReference.Render(IInternalContextAdapter context, TextWriter writer)
at NVelocity.Runtime.Parser.Node.ASTBlock.Render(IInternalContextAdapter context, TextWriter writer)
at Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives.CaptureForDirective.Render(IInternalContextAdapter context, TextWriter writer, INode node)
at NVelocity.Runtime.Parser.Node.ASTDirective.Render(IInternalContextAdapter context, TextWriter writer)
at NVelocity.Runtime.Parser.Node.SimpleNode.Render(IInternalContextAdapter context, TextWriter writer)
at NVelocity.Template.Merge(IContext context, TextWriter writer)
at Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine.RenderLayout(String layoutName, String contents, IContext ctx, TextWriter output)
at Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine.ProcessLayoutRecursively(StringWriter writer, IEngineContext context, IController controller, IControllerContext controllerContext, IContext ctx, TextWriter finalOutput)
at Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine.Process(String viewName, TextWriter output, IEngineContext context, IController controller, IControllerContext controllerContext)
现在你会看到它正在寻找
d:\._GIT_\HIV PROJECT\stellar\Services\site_controlls\themeService.cs
但在它运行的服务器上
C:\inetpub\wwwroot\domain.com\Services\site_controlls\themeService.cs
现在我确定它不是在服务器上硬编码的,我什至在获取应用程序路径的方法上对 webconfig 中的根路径进行了近乎硬编码的长度。
public static String root_path() {
NameValueCollection section = (NameValueCollection)ConfigurationManager.GetSection("site_config");
string setting = section["root"];
if (String.IsNullOrWhiteSpace(setting)) return setting;
String path = VirtualPathUtility.ToAppRelative("~");
if (!String.IsNullOrWhiteSpace(path)) return path;
path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath).Replace("bin", "");
return path;
}
web.config 所在的位置
<site_config>
<add key="installed" value="False" />
<add key="root" value="C:\inetpub\wwwroot\domain.com" />
</site_config>
因此,令人困惑的是,当我获得服务器的日志时,我最终得到的是开发电脑的错误日志中的路径,我在而不是服务器上工作。
问题是,除了硬编码我的我,什么条件允许应用程序未加载、未使用但开发路径的路径?它在项目dll中吗?