C# Asp.net mvc指定的UserAgent没有会话Id

C# Asp.net mvc指定的UserAgent没有会话Id,c#,asp.net-mvc,session,iis,redirect,C#,Asp.net Mvc,Session,Iis,Redirect,我的项目Asp.net mvc 1.0和.net framework 2.0有问题。我的应用程序托管在IIS 7.5上。我的身份验证表单如下所示: <authentication mode="Forms"> <forms protection="All" loginUrl="~/Account/LogOn" timeout="60" cookieless="UseUri" /> </authentication> <htt

我的项目Asp.net mvc 1.0和.net framework 2.0有问题。我的应用程序托管在IIS 7.5上。我的身份验证表单如下所示:

  <authentication mode="Forms">
      <forms protection="All" loginUrl="~/Account/LogOn" timeout="60" cookieless="UseUri" />
    </authentication>
    <httpRuntime executionTimeout="1000" maxRequestLength="600000" />
    <sessionState mode="InProc" cookieless="UseUri" timeout="60">
    </sessionState>
我发现的另一个线索是“错误”连接中没有会话-会话对象为null

总而言之:使用指定的用户代理连接到我的应用程序网页会产生无限重定向循环,这可能是因为缺少会话ID。可能是什么问题

编辑:我发现包含“UP.Browser”的用户代理与移动相关。当我把“无Cookie”改为“UseCookies”时,一切正常。为什么选项“UseUri”不适用于手机

EDIT2:/admin->托管在指定IP地址上的我的网页。 良好的联系:

错误连接:

抱歉,我不知道如何将这些图像放大。

因此,您将两个不同的值放入URI,一个用于会话,一个用于表单,这可能会创建一个冗长的URI:

“此功能的主要限制是可以存储在URL中的数据量有限。此功能不针对IE等常见浏览器,因为这些浏览器确实支持cookie,并且不需要此功能。不支持cookie的浏览器是移动设备(如手机)上的浏览器。”,并且这些浏览器通常会严格限制它们支持的URL的大小。因此,使用此功能时要小心,请确保应用程序生成的无Cookie字符串较小。”

我猜无限重定向循环的关键在于以下功能:

"// Step 5: We can't detect if cookies are supported or not. So, send a 
//         challenge to the client. We do this by sending a cookie, as
//         well as setting a query string variable, and then doing a 
//         redirect back to this page. On the next request, if cookie
//         comes back, then Step 3 will report that "cookies are 
//         supported". On the other hand, if the next request does not
//         have any cookies, then Step 4 will report "cookies not
//         supported".
SetAutoDetectionCookie();
Redirect(ThisPage + Our_auto_detect_challenge_variable);"

不幸的是,这听起来有点像是对架构的重新思考,因为现在可能会影响到站点的完整路径,您可能不得不放弃表单身份验证的自动处理。

正如您所说的问题是针对移动浏览器的,我认为这个问题仅限于设备(移动设备)如上面的MSDN参考文章所述,当cookies不受支持且URL大小增加且移动浏览器严重限制该大小时。

我的解决方案是使用重写规则将包含“UP.browser”的用户代理更改为其他内容。一切正常;)

编辑:我发现了另一条线索。 在移动浏览器中,如果用户代理包含“UP.browser”,则必须在地址的末尾添加斜杠。 总之:

对于与“UP.Browser”无关的用户代理,一切正常。 包含“UP.Browser”所需地址的用户代理,如:

http://addr/controller/

我不知道为什么有必要。有什么想法吗?

您能检查一下querystring参数是否通过了吗?如果您使用的是chrome开发工具,您可能需要在网络选项卡中检查URL。作为查询字符串参数,您是指URL中的会话id吗?因为我没有发送任何参数。为什么要使用cookieless=“UseUri”?@Kiquenet抱歉,那是5年前的事了,不知道:)在你最新的应用程序(ASP.NET MVC)中运行的源代码?如果它适用于具有默认UserAgent的Firefox,而不适用于具有UserAgent UP.Browser的Firefox,它的URI长度会是多少?所以uri大小限制不能成为原因…长度可能不是问题,加载页面时不会生成表单id。此时只提供了会话id,该id不太长
"// Step 5: We can't detect if cookies are supported or not. So, send a 
//         challenge to the client. We do this by sending a cookie, as
//         well as setting a query string variable, and then doing a 
//         redirect back to this page. On the next request, if cookie
//         comes back, then Step 3 will report that "cookies are 
//         supported". On the other hand, if the next request does not
//         have any cookies, then Step 4 will report "cookies not
//         supported".
SetAutoDetectionCookie();
Redirect(ThisPage + Our_auto_detect_challenge_variable);"
http://addr/controller/