ASPDotNetStorefront アプリケーションで、「偽の」ログインをシミュレートします。SkinBase.cs
ファイル内、メソッド内protected override void OnPreInit(EventArgs e)
でコードを使用して関数を呼び出します。
public void SetTempUserForNonLoginStore()
{
if (AppLogic.StoreID() == 2) //store which doesn't need login
{
string path = HttpContext.Current.Request.Url.AbsolutePath.ToLower();
if (path.Contains("signin.aspx") == false)
{
m_ThisCustomer = new Customer(TempCustomerID);
AppLogic.ExecuteSigninLogic(0, m_ThisCustomer.CustomerID);
string cookieUserName = m_ThisCustomer.CustomerGUID.ToString();
FormsAuthentication.SetAuthCookie(cookieUserName, true);
m_ThisCustomer.ThisCustomerSession.UpdateCustomerSession(null, null);
HttpCookie authCookie = Response.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null && !AppLogic.AppConfigBool("GoNonSecureAgain"))
{
authCookie.Secure = AppLogic.UseSSL() && AppLogic.OnLiveServer();
}
}
}
}
そして、このコードは機能します。しかし、セッションが期限切れになり、"Session Expire" - ポップアップが表示され、ユーザーが "OK" をクリックすると、ASPDNSF は Signin.aspx - ページにリダイレクトします。Signin.aspx ページで、ログイン フォームを非表示にし、次のコードで「戻る」ボタンを追加しました。
protected void btn_GoBack_Click(object sender, EventArgs e)
{
string returnURLParam = HttpContext.Current.Request["ReturnUrl"];
if (string.IsNullOrWhiteSpace(returnURLParam))
{
returnURLParam = "~/";
}
Response.Redirect(returnURLParam);
}
前のページにリダイレクトします。しかし、そのページにリダイレクトすると、.css ファイルと .js ファイルが読み込まれません。ブラウザの開発ツールでは、これらのリソースへのリクエストは次のとおり
{{DOMAIN}}/SignIn.aspx?ReturnUrl={{Resource path}}
です。例:
{{DOMAIN}}/SignIn.aspx?ReturnUrl=%2FApp_Themes%2FSkin_1%2Fmystyles.css
{{DOMAIN}}/SignIn.aspx?ReturnUrl=%2Fjscripts%2Fjquery.min.js
これらのリソースには承認されたユーザーが必要なようです。しかし、私のweb.configファイルには
<location path="jscripts">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
<location path="App_Themes">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
したがって、これらのリソースにログインする必要はありません。
ありがとうございました!