我正在构建一个托管在ASP.NET Web App上的silverlight应用程序. / IIS7 /启用SSL的网站.
为了安全起见,我将Silverlight页面放在ASP.NET Web应用程序的Members文件夹中,并禁止匿名用户访问.(参见下面的web.config)
当用户尝试访问Members文件夹下的页面时,它们会被重定向到https://www.ssldemo.com/authenticationtest/login.aspx.(请参阅下面的web.config)
(我已将www.ssldemo.com映射到127.0.0.1).
为了安全起见,我在login.aspx中切换到HTTPS,并在验证后返回HTTP.
下面是login.aspx.cs的代码.
protected void Page_Load(object sender,EventArgs e) { LoginControl.LoggedIn += new EventHandler(LoginControl_LoggedIn); } void LoginControl_LoggedIn(object sender,EventArgs e) { //for going to ReturnURL & switching back to HTTP string serverName = HttpUtility.UrlEncode(Request.ServerVariables["SERVER_NAME"]); string returnURL = Request["ReturnURL"]; Response.Redirect(ResolveClientUrl("http://" + serverName + returnURL)); }
问题是,当我将另一个应用程序部署到http://www.ssldemo.com/authenticationtest/members/AnotherApplication/时
并打开http://www.ssldemo.com/authenticationtest/members/AnotherApplication/default.aspx,
用户被重定向到https://www.ssldemo.com/authenticationtest/login.aspx?ReturnUrl=%2fauthenticationtest%2fmembers%2fanotherapplication%2fdefault.aspx.
但即使我在登录页面输入正确的凭据,我也会被重定向到同一个登录页面,而不是ReturnUrl.当我看着提琴手时,它说“302物体移到了这里.”
谢谢你的阅读!任何输入将非常感激.
<configuration> <connectionStrings> <add name="CompanyDatabase" connectionString="Data Source=192.168.0.2;Initial Catalog=SomeTable;User ID=Username;Password=P@ssword" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Forms"> <forms slidingExpiration="true" timeout="15" loginUrl="https://www.ssldemo.com/authenticationtest/login.aspx" defaultUrl="~/Members/Default.aspx" > </forms> </authentication> <!--Custom Membership Provider--> <membership defaultProvider="MyMembershipProvider" userIsOnlineTimeWindow="15"> <providers> <clear /> <add name="MyMembershipProvider" type="AuthenticationTest.Web.MyMembershipProvider" connectionStringName="CompanyDatabase" applicationName="AuthenticationTest.Web"/> </providers> </membership> </system.web> <!--securing folders--> <location path="Members"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> </configuration>
解决方法
成员(子应用程序)下面的应用程序继承了上面的设置,因此它会获取您的身份验证设置,这就是它进入该登录页面的原因.
它永远不会起作用的原因是如何加密票证.除非您执行一些额外配置,否则无法在应用程序之间重复使用故障单.这会阻止用户在一个应用中进行身份验证,然后访问服务器上的每个其他应用. Asp.Net通过为每个应用程序创建一个新的随机密钥来实现此目的.
首先,您需要将enableCrossAppRedirects = true添加到forms元素.然后,您需要将两个应用程序中的MachineKey设置为相同,以便两个应用程序都可以解码身份验证票证.
这个页面可能对http://msdn.microsoft.com/en-us/library/eb0zx8fc.aspx有帮助