开发者

"Failed to map the path" error in Global.asax

开发者 https://www.devze.com 2023-04-10 13:20 出处:网络
I am a newbie when coming to C#, so any help will be appreciated. The project is Web Application in C# using VS2005.

I am a newbie when coming to C#, so any help will be appreciated. The project is Web Application in C# using VS2005. This is the code in Global.asax that give the error:

System.Configuration.Configuration rootWebConfig =
     System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/" + strVirtualDirectory);

AS i understand the code will be runned on IIS. the [strVirtualDirectory] is the name of the Virtual Directory (physical dir will be the source folder) in the Default Web Site on IIS.

When I still used Win XP, everything worked okay. After upgrade to Win 7 Pro, I had setup Virtual Directory on IIS 7 the same way as on Win XP. However, the code fail to recognize the Virtual Directory.

Can anyone help me solve this problem. I am sorry for my bad English.


Sorr开发者_开发知识库y for the late reply. I am really busy in the past few days.

The Global.asax is not allowed to change so my intention is to know the way to config the IIS7 to be able to work with the VS2005 and the project.

If the method is to complicate, maybe I should just return to Windows XP or run Win XP with VM Player.


This page should give you all the information you need on creating, reading and setting iis7 parameters on 32 or 64 bit systems. Hope that helps.

http://forums.iis.net/t/1139885.aspx


Try

System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)


Generally you can call Server.MapPath("~/) to access the root directory, e.g. Server.MapPath("web.config").

But to open the web.config file you can just path null as a parameter to open the web.config file. If you want the same behavior under IIS 7, you can run the web in classic mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号