和很多人一样,我遇到了CS0103问题,但在使用IIS7.5时,我找不到现有主题的好解决方案
奇怪的是:
此错误涉及的类在BusinessLogicWrapper.cs中的App_Code文件夹中(图标在Visual Studio中是灰色的。这是否意味着它没有被考虑?或者只是因为它是一个特殊的文件夹?)。
我试图在SessionProcessing.ashx的开头添加一个include BusinessLogic;
,但它没有工作:编译器只停在第3行而不是30号,说它不知道它包含什么。 ..
我感谢你的帮助,
更多信息:
部分解决方法是将我的虚拟目录的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>
答案 0 :(得分:2)
如何为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...
答案 1 :(得分:1)
解决方法(如果您有更好的想法,请留下评论)将我的虚拟目录的bin文件夹放入根目录。
请注意,我不再有“服务器错误”(目前至少),但该网站仍然无法正常工作(我认为不同文件的路径存在问题......)。
这不是一个明确的答案(从我自己到其他人),但也许它可以为更多实验用户提供一些想法!