2010-06-10 145 views
5

我構建了一個託管在ASP.NET Web App上的Silverlight應用程序。 /啓用IIS7/SSL的網站。
爲了安全起見,我把我的Silverlight頁面一個成員文件夾中的ASP.NET Web應用程序,並限制來自匿名用戶的訪問。(見下面的web.config)ASP.NET登錄頁面重定向問題

當用戶嘗試訪問成員文件夾下的頁面,他們被重定向到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;[email protected]" /> 
</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> 

回答

3

以下會員的應用程序(子應用程序)繼承與上面的設置,所以它拿起你的身份驗證設置,這就是爲什麼它去到登錄頁面。

它從來沒有工作的原因是與票據如何加密。除非你做了一些額外的配置,否則票據不能在應用程序之間重複使用。這會阻止用戶在一個應用程序中進行身份驗證,然後訪問服務器上的每個其他應用Asp.Net通過爲每個應用程序創建一個新的隨機密鑰來做到這一點。

首先,您需要將enableCrossAppRedirects = true添加到forms元素。然後,您需要在兩個應用程序中將MachineKey設置爲相同,以便兩個應用程序都可以解碼身份驗證票證。

此頁面可能會有幫助http://msdn.microsoft.com/en-us/library/eb0zx8fc.aspx