Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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
ASP.Net Web应用程序请求.Params[“AUTH_USER”是空字符串_Asp.net_Visual Studio 2012 - Fatal编程技术网

ASP.Net Web应用程序请求.Params[“AUTH_USER”是空字符串

ASP.Net Web应用程序请求.Params[“AUTH_USER”是空字符串,asp.net,visual-studio-2012,Asp.net,Visual Studio 2012,我正在VisualStudio2012中构建一个ASP.NET4.5Web应用程序。我已将以下代码放在我的Global.asax.cs中: protected void Session_Start(object sender, EventArgs e) { Session["LastError"] = ""; // Code that runs when a new session is started string delimStr =

我正在VisualStudio2012中构建一个ASP.NET4.5Web应用程序。我已将以下代码放在我的Global.asax.cs中:

protected void Session_Start(object sender, EventArgs e)
    {
        Session["LastError"] = "";
        // Code that runs when a new session is started
        string delimStr = @"\";
        char[] delimiter = delimStr.ToCharArray();
        string[] requestor = Request.Params["AUTH_USER"].ToString().Split(delimiter, 2);
        string requestorEID = requestor[1];
        Session["UserID"] = requestorEID;

        //Get User data (name, roleid, rolename) from database
        List<SqlParameter> paramList = new List<SqlParameter>();
        paramList.Add(new SqlParameter("@EmployeeID", requestorEID));
        DataTable dtUserList = KLClassLibrary.KLDataAccessLayer.ExecuteSelect("GetUserData", paramList, "OffSiteCN");

        if (dtUserList.Rows.Count > 0)
        {
            Session["EmployeeName"] = dtUserList.Rows[0]["EmployeeName"].ToString();

        }
        else
        {
            Session["LastError"] = "You Are Not Authorized To Access This Application";
            Session["EmployeeName"] = "";
            Response.Redirect("~/ErrorPage.aspx");
        }
    }

Request.Params[“AUTH_USER”]等于空字符串。虽然我不熟悉VS2012和.NET4.5,但我已经成功地使用这段代码多年了。出什么问题了?

这不是一个完整的解决方案,但我可以使用以下代码创建一个解决方案:

string requestor = Request.LogonUserIdentity.Name.ToString();
        int requestor_length = requestor.Length;
        string requestorEID = requestor.Substring(requestor_length - 5, 5);
        Session["UserID"] = requestorEID;
确保在项目的属性中启用了“Windows身份验证”(它位于属性列表的最底部)。这将允许IISExpress使用windows身份验证

然后确保在web.config的system.web授权部分system.webServer或两者中拒绝匿名用户的访问

对于IIS 6.5或以下版本:

<system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
</system.web>


您是否一直在会话中使用它?如果是这样的话,我认为您必须在会话开始之前对用户进行身份验证,这可能在web.config中。如果是这样,您以前使用的IIS版本是什么,可能是IIS 6?在IIS 7+中,需要在system.web服务器中设置您可能在system.web中设置的设置。非常感谢!我总是把这个代码放在Session\u Start中。我在web.config中将身份验证模式设置为Windows。我没有使用IIS,而是使用VisualStudio 2012中内置的web服务器来启动我的应用程序。它一直失败,因为AUTH_用户为空。感谢您提供此信息!我已将IIS 7授权部分添加到我的Web.config中,但在项目的属性中没有看到任何有关Windows身份验证的内容。我已经查看了属性选项卡和属性页面。我还访问了Visual Studio中解决方案资源管理器下的“属性”部分,查看了PublishProfiles下的pubxml文件和AssemblyInfo.cs文件。我错过了什么?再次感谢你!我添加了我正在讨论的财产的图像。这不是您的错,如果您右键单击并选择“属性”,会弹出一个不同的属性窗口。所以你需要打开“属性”窗口,然后选择网站项目。我想我看到了问题所在——你说的是一个网站项目,而我说的是一个web应用程序项目。至少,我在创建网站项目时看到了您所说的属性,但在创建web应用程序项目时肯定看不到。现在,您知道如何使用web应用程序解决我的问题吗?非常感谢你花这么多时间在这上面!诚然,我并没有使用2012,但在2013年,我在一个Web应用程序和一个网站上看到了Windows身份验证。我不记得是2010年还是2012年使用IIS express代替卡西尼号——我知道2013年卡西尼号不再是一种选择。调试时您使用的是Cassini、IIS Express还是本地IIS?在我的项目属性中的Web下,我选择了使用Visual Studio Development Server,我相信这就是Cassini。无论如何,如果我将其更改为本地IIS Web服务器(此处默认使用IIS Express),我确实会看到您指示的Windows身份验证属性,但Request.Params[“AUTH_USER”]仍然是空字符串。所以我还是被难住了。
<system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
</system.web>
<system.webServer>
  <security>
    <authorization>
      <add accessType="Deny" users="?"/>
    </authorization>
  </security>
</system.webServer>