Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WebMethod在Visual Studio中工作,但不在IIS7(HTTP状态500)上工作_C#_Asp.net_Ajax_Webmethod - Fatal编程技术网

C# WebMethod在Visual Studio中工作,但不在IIS7(HTTP状态500)上工作

C# WebMethod在Visual Studio中工作,但不在IIS7(HTTP状态500)上工作,c#,asp.net,ajax,webmethod,C#,Asp.net,Ajax,Webmethod,我有一个通过Ajax调用的WebMethod。该代码通过VisualStudio可以完美地工作,但是一旦我将其发布到IIS7并登录,就会收到一个内部服务器错误(HTTP状态500) 使用Fiddler,我可以看到以下内容: 无法加载文件或程序集的System.Web.Extensions,版本=4.0.0, 区域性=中性,PublicKeyToken=31bf3856ad364e35'或其 依赖关系。系统找不到指定的文件 我想我可能需要web.config中的一些东西,但我不确定 代码如下: 阿

我有一个通过Ajax调用的WebMethod。该代码通过VisualStudio可以完美地工作,但是一旦我将其发布到IIS7并登录,就会收到一个内部服务器错误(HTTP状态500)

使用Fiddler,我可以看到以下内容:

无法加载文件或程序集的System.Web.Extensions,版本=4.0.0, 区域性=中性,PublicKeyToken=31bf3856ad364e35'或其 依赖关系。系统找不到指定的文件

我想我可能需要web.config中的一些东西,但我不确定

代码如下:

阿贾克斯


可能的解决方案:

我移除了可能存在问题的区域。我现在只需要浏览一下我的网站,看看是否一切正常

<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<httpModules>
  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>

在我看来,您的某些资源不可用,因此应将其作为Emmbed资源放置。在构建解决方案之前,右键单击文件->属性->构建操作->Emmbed Resource

如果您的web方法是静态的,请删除static

尝试从中更改web配置
[System.Web.Services.WebMethod(BufferResponse = false, EnableSession = true)]
    public object Gety()
    {

        if (HttpContext.Current.Session["LoggedInUserType"].ToString() == GlobalVaribles.UserLogged)
        {
            var viewUserDashboardCountsValueBussinessLogicLayer = new ViewUserDashboardCountsValueBLL();
            var userDashboardValues =
                 viewUserDashboardCountsValueBussinessLogicLayer.GetUserDashboardCountByUserId(Convert.ToInt64(HttpContext.Current.Session["CompanyID"]));
            return userDashboardValues;
        }
        else
        {
            var viewConsultantDashboardCountValueBussinessLogicLayer =
                new ViewConsultantDashboardCountValueBLL();
            var consultantDashboardValues =
                viewConsultantDashboardCountValueBussinessLogicLayer.GetConsultantDashboardCountByUserId(Convert.ToInt64(HttpContext.Current.Session["LoggedUserId"]));
            return consultantDashboardValues;
        }
    }
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<httpModules>
  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>