C# ASP.NET、Windows身份验证和查询字符串

C# ASP.NET、Windows身份验证和查询字符串,c#,asp.net,iis,C#,Asp.net,Iis,情景: 一个ASP.NET C#网站,位于windows server 2012和sqlserver 2014上。通过web.config中设置的Windows身份验证进行用户身份验证,如下所示: <authentication mode="Windows" /> <authorization> <deny users="?" /> <allow users="*" /> </authorization>

情景: 一个ASP.NET C#网站,位于windows server 2012和sqlserver 2014上。通过web.config中设置的Windows身份验证进行用户身份验证,如下所示:

<authentication mode="Windows" />
<authorization>
        <deny users="?" />
        <allow users="*" />
</authorization>   
页面default.aspx使用它从数据库加载数据(例如)

由于用户未经过身份验证,Windows对话框需要用户名和密码。 用户插入正确的凭证,并对其进行身份验证。 页面

不见了

用户希望按如下方式打开链接

http://<mydomain>/default.aspx
http://<mydomain>/default.aspx?id=1
http://<mydomain>/default.aspx?id=1
<system.web>
    <customErrors mode="Off" />
    <pages validateRequest="false" controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/>

    <authentication mode="Windows" />
    <authorization>
            <deny users="?" />
            <allow users="*" />
    </authorization>   

    <membership>
    <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
    </providers>
    </membership>
    <profile>
        <providers>
            <clear />
            <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
        </providers>
    </profile>
    <roleManager enabled="false">
    <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
        </providers>
    </roleManager>
        <sessionState mode="InProc" timeout="120" />
</system.web>
http:///default.aspx?id=1
但在验证之后,页面将被删除

http://<mydomain>/default.aspx
http:///default.aspx
已加载。缺少查询字符串。因此,用户必须在浏览器中再次插入url

http://<mydomain>/default.aspx?id=1
http:///default.aspx?id=1
web.config文件如下所示

http://<mydomain>/default.aspx
http://<mydomain>/default.aspx?id=1
http://<mydomain>/default.aspx?id=1
<system.web>
    <customErrors mode="Off" />
    <pages validateRequest="false" controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/>

    <authentication mode="Windows" />
    <authorization>
            <deny users="?" />
            <allow users="*" />
    </authorization>   

    <membership>
    <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
    </providers>
    </membership>
    <profile>
        <providers>
            <clear />
            <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
        </providers>
    </profile>
    <roleManager enabled="false">
    <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
        </providers>
    </roleManager>
        <sessionState mode="InProc" timeout="120" />
</system.web>

在url中进行身份验证后是否可以维护查询字符串?IIS中有这样的保护,在验证之前不考虑查询字符串吗?


感谢您在登录页面(或您将登录表单放在任何地方)的代码,请尝试以下操作:

// Login Button Click Event
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //verify user's credential 
            // if it is correct then 
            // do whatever you want, create a session, cookie etc..., then redirect user:     
                        string strRedirect;
                        strRedirect = Request["ReturnUrl"];
                        if (strRedirect == null) strRedirect = "/"; // if there isn't any query string then redirect user to default page
                        Response.Redirect(strRedirect, true);
            // else display wrong username/password message...
        }

您的web.config是否已禁用?您确定正在使用IIS/Website/Authentication中设置的“Windows身份验证”以及所有其他选项吗?或者您使用的是表单登录,但经过active directory验证?您是否已在域中,您的帐户是否有权访问该网站?“插入Windows凭据”对话框/进程/输入实际上是什么样子的?使用Windows身份验证时,如果您具有访问权限,则不应收到提示。只需在问题中添加一个web.config文件部分,不使用表单登录,也不使用active directory。使用的帐户是服务器的用户,而不是域的一部分。打开页面时,会出现一个Windows对话框,要求输入用户名和密码。身份验证后,您可以访问该网站的所有页面。它是ASP.NET c#中IIS上的一个网站,用于管理我们的客户后端。(Windows Server 2012和Sql Server 2014)。示例:当客户打开支持请求单时,会向支持团队发送一封电子邮件,其中包含以下链接:http:///ticket.aspx?id=345'如果您已通过身份验证,则网页ticket.aspx会显示请求编号345,这要感谢查询字符串。如果未授权,则会出现一个Windows对话框。身份验证后,您将进入页面的http:///ticket.aspx“不是”http:///ticket.aspx?id=345'作为链接。使用Windows身份验证,而不是窗体登录。对于登录,将出现需要凭据的Windows对话框。没有登录表单。此代码极易受影响,不应按原样使用。