Yeo*_*nho 5 asp.net authentication deployment redirect login
我正在构建一个托管在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));
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我将另一个应用程序部署到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>
Run Code Online (Sandbox Code Playgroud)
成员下面的应用程序(子应用程序)继承了上面的应用程序的设置,因此它会获取您的身份验证设置,这就是它进入该登录页面的原因。
它不起作用的原因与票证的加密方式有关。除非您进行一些额外的配置,否则票证无法在应用程序之间重复使用。这会阻止用户在一个应用程序中进行身份验证,然后访问服务器上的所有其他应用程序。Asp.Net 通过为每个应用程序创建一个新的随机密钥来实现这一点。
首先,您需要将enableCrossAppRedirects=true 添加到forms 元素中。然后,您需要将两个应用程序中的 MachineKey 设置为相同,以便两个应用程序都可以解码身份验证票证。
此页面可能有帮助http://msdn.microsoft.com/en-us/library/eb0zx8fc.aspx
| 归档时间: |
|
| 查看次数: |
2942 次 |
| 最近记录: |