【问题标题】:Compiler Error Message: CS0103: The name 'BusinessLogic' does not exist in the current context编译器错误消息:CS0103:当前上下文中不存在名称“BusinessLogic”
【发布时间】:2013-03-15 16:20:08
【问题描述】:

像很多人一样,我遇到了 CS0103 问题,但在使用 IIS7.5 时我没有找到针对现有主题的好的解决方案

奇怪的是:

  • 网站在 IIS5.1 / XP 下运行良好(至少没有这个问题)
  • 网站在 IIS7.5 Express / XP 下运行良好(从 Visual Studio 2010 运行时)
  • 网站在 IIS7.5 Express / W7 下运行良好(从 Visual Studio 2010 运行时)
  • 但我在使用 IIS7.5 / W7 时遇到此错误

与此错误有关的类位于 App_Code 文件夹中的 BusinessLogicWrapper.cs 中(Visual Studio 中的图标为灰色。这是否意味着它没有被考虑在内?或者仅仅是因为它是一个特殊的文件夹?)。

我试图在 SessionProcessing.ashx 的开头添加一个 include BusinessLogic; 但它不起作用:编译器只是停在第 3 行而不是第 30 行,说它不知道它必须包含什么...

谢谢你的帮助,


更多信息:

  • 我正在运行网站的预编译版本
  • 一开始它是为 IIS5.1 设计的

部分解决方法是将我的虚拟目录的 bin 文件夹放入根目录。

请注意,我不再有“服务器错误”(至少目前如此),但该网站仍然无法正常工作(我认为不同文件的路径存在问题......)。

这不是一个确定的答案(从我自己到我自己和其他人),但也许它可以为更多实验用户提供一些想法!


网站显示的500错误:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'BusinessLogic' does not exist in the current context

Source Error:


Line 28:                                 (context.Request.HttpMethod == "POST" && context.Request.Params["action"] == "DELETE"))
Line 29:                 {
Line 30:                     BusinessLogic.Wrapper.WRITE_TRACE(BusinessLogic.TraceLevel.MEDIUM, "SessionProcessing.ashx End session", "sid:" + sid);
Line 31:                     int res = BusinessLogic.Wrapper.removeSession(sid);
Line 32: 

Source File: c:\Users\blabla\PrecompiledWeb\Web2\SessionProcessing.ashx    Line: 30 

SessionProcessing.ashx 的开头:

<%@ WebHandler Language="C#" Class="getsession" %>

using System;
using System.Web;
using System.Text;

public class getsession : IHttpHandler, System.Web.SessionState.IReadOnlySessionState
{

    public void ProcessRequest (HttpContext context) {
        context.Response.Clear();
        context.Response.TrySkipIisCustomErrors = true;

        String sid = context.Request.Params["sessionid"];

        try
        {
            if (sid != null)
            {
                //###############################################
                //###############################################
                if (context.Request.HttpMethod == "DELETE" ||
                                (context.Request.HttpMethod == "POST" && context.Request.Params["action"] == "DELETE"))
                {
                    BusinessLogic.Wrapper.WRITE_TRACE(BusinessLogic.TraceLevel.MEDIUM, "SessionProcessing.ashx End session", "sid:" + sid);
                    int res = BusinessLogic.Wrapper.removeSession(sid);

最后是树的图像:http://i.stack.imgur.com/szbhA.png


App_Code/BusinessLogicWrapper.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Runtime.InteropServices;

namespace BusinessLogic
{
    /// <summary>
    /// Summary description for BusinessLogicWrapper
    /// </summary>
    public class Wrapper
    {
        //Init
        [DllImport("BusinessLogicLib.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int init(string loginFilePath, string remoteServerName, string[] itemsConnection, int cItems);

web.config(实际上有9条重写规则)

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpCookies domain="localhost"/>
  </system.web>
  <system.webServer>
    <!-- add support for ogg files-->
    <staticContent>
      <mimeMap fileExtension=".oga" mimeType="audio/ogg"/>
      <mimeMap fileExtension=".spx" mimeType="audio/ogg"/>
      <!-- <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/> -->
    </staticContent>
    <!--Disable gzip compression (otherwise server pushed data is cut when arriving on the client) -->
    <urlCompression doStaticCompression="true" doDynamicCompression="false"/>
    <rewrite>
      <rules>
        <rule name="COW API session creation">
          <match url="^session$"/>
          <action type="Rewrite" url="SessionProcessing.ashx"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

【问题讨论】:

    标签: c# asp.net iis iis-7.5 iis-express


    【解决方案1】:

    为您的BusinessLogic(Wrapper) 类添加适当的命名空间怎么样?

    <%@ WebHandler Language="C#" Class="getsession" %>
    
    using System;
    using System.Web;
    using System.Text;
    using [YourProjectName].App_Code
    

    如果是网站项目,请尝试在您的 BusinessLogicWrapper.cs 文件中完全删除命名空间:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Text;
    using System.Runtime.InteropServices;
    
    
        public class Wrapper
        {
            //Init
            [DllImport("BusinessLogicLib.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
            public static extern int init(string loginFilePath, string remoteServerName, string[] itemsConnection, int cItems);
    

    然后访问您的 Wrapper 类,例如:Wrapper.WRITE_TRACE...

    【讨论】:

    • 感谢您的回答!但问题是:据我所知,我并没有真正的项目名称 9),因为它是一个 Web 应用程序(这就是我收到 500 错误的原因)。我试着写using App_Code;,但因为它不是一个命名空间......我在哪里可以找到我的项目名称(我真的是 ASP 的新手,我正在做一个我没有开发的项目)?还是谢谢你!
    • 当你说“网络应用程序”时,我相信你的意思是它是一个“网站项目”(文件->新网站)。 Web 应用程序项目具有命名空间和项目名称。
    • 很抱歉没有使用适当的词汇。是的,这是一个网站项目。
    • 我在我的帖子中添加了一个“部分解决方法”,使用根目录。它解决了编译错误。但是网站仍然没有工作(当我尝试登录时,它无法识别我的标识符,可能是因为它们存储在一个文件中,并且从 bin 文件夹到该文件的相对路径已更改)
    【解决方案2】:

    一种解决方法(如果您有更好的想法,请离开 cmets)是将我的虚拟目录的 bin 文件夹放入根目录。

    请注意,我不再有“服务器错误”(至少目前如此),但该网站仍然无法正常工作(我认为不同文件的路径存在问题......)。

    这不是一个确定的答案(从我自己到我自己和其他人),但也许它可以为更多实验用户提供一些想法!

    【讨论】:

    • 一个实用的“解决方法”是移动根文件夹中的所有内容,而不是虚拟文件夹(因此相关链接仍然有效)。当然,问题是根文件夹只有一个,所以如果我需要部署其他网站......我仍然对你的解决方案感兴趣!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2019-01-05
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多