0

在我的 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();
                }
            }
        }
    }

这段代码有效。但是当会话过期并且“会话过期” - 弹出窗口出现并且用户单击“确定”时,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>

因此,这些资源不需要登录。

谢谢!

4

1 回答 1

0

为了获得更好的性能并照顾需要登录的静态文件,请禁用静态文件通过 asp.net 管道进行处理。通过在根文件夹的 web.config 中将 runAllManagedModulesForAllRequests 更改为 false。

于 2016-07-28T19:10:23.103 回答