IIS looking at wrong path for MVC configuration file

759 views Asked by At

When I run MVC4 my application using Visual Studio Development Server, my application is able to load all configuration files correctly. But when I try to run it under the Local IIS Web server, it throws this error

{"Could not find a part of the path 'C:\\Windows\\SysWOW64\\inetsrv\\~\\nhibernate.config'."}

It's looking at the wrong folder. The config file is directly in the root of my web project. Why is this happening. How can I fix it. I'm pretty sure that nhibernate looks for this file in order to load it's properties. Unless you know how to move nhibernate configuration files into the web.config file, please don't recommend that, I get a "Unrecognized configuration section hibernate-configuration" when ever I copy it over

Edit: by the way, I'm pretty sure it's looking at the following key in appSettings my app settings section

<add key="nhibernate.config" value="~/nhibernate.config" />

Edit2: here is the stack trace that goes into how Nhibernate is getting this value, and trying to find the configuration file

at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader)
at NHibernate.Cfg.Configuration.Configure(XmlReader textReader)
at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig)
at NHibernate.Cfg.Configuration.Configure(String fileName)
at AndroMDA.NHibernateSupport.DefaultSessionManager.BuildSessionFactory()
1

There are 1 answers

0
DrSammyD On BEST ANSWER

So it wasn't actually NHibernate that was using this file. My boss decided to use something called AndroMDA to generate code, and part of that generation was some NHibernate Support that I couldn't see into.

If anybody is interested, I created a new implementation of ISessionManager, which looks exactly like DefaultSessionManager except for the following member function and variable.

public class ServerMapSessionManager : ISessionManager
{
    //other interface implementation...//
    public static HttpServerUtility Server { get; set; }
    public String TranslateConfigPath(String virtualPath)
    {
        return Server.MapPath("/"+virtualPath);
    }
}

Then in App_start I call the following

        SessionManagerFactory.SessionManager = new MVCFramework.Core.Common.ServerMapSessionManager();
        MVCFramework.Core.Common.ServerMapSessionManager.Server = Server;