即使到期日期尚未结束,FormsAuthentication也会重定向到登录页面

时间:2018-12-13 06:44:34

标签: authentication webforms forms-authentication

我已经使用FormsAuthentication创建了Httpcookie。我写如下。过期时间创建为2019-12-13T06:44:35.508Z(镀铬)。

在web.Config文件中;

import UIKit

class ViewController: UIViewController {

    var editInfoScrollView : UIScrollView = {
        let view = UIScrollView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.isUserInteractionEnabled = true
        view.alwaysBounceVertical = true
        view.isScrollEnabled = true
        view.contentSize.height = 700
        view.backgroundColor = UIColor.red.withAlphaComponent(0.3)
        // Does nothing because `translatesAutoresizingMaskIntoConstraints = false`
        // Instead, set the content size after activating constraints in viewDidAppear
        //view.frame = CGRect(x: 0, y: 220, width: 375, height: 400)
        return view
    }()

    var vehicleNumberLabel: UILabel = {
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        label.textColor = UIColor.black
        label.text = "Vehicle Number"
        label.textAlignment = .left
        return label
    }()

    lazy var vehicleNumberButton: UIButton = {
        let button = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        button.tag = 1
        button.setTitleColor(UIColor.black, for: .normal)
        button.setTitle("Go to Vehicle", for: .normal)
        button.tintColor = UIColor.white
        button.backgroundColor = UIColor.clear
        button.layer.cornerRadius = 30 // about half of button.frame.height
        button.layer.borderColor = UIColor.black.cgColor
        button.layer.borderWidth = 2.0
        button.layer.masksToBounds = true
        button.addTarget(self, action: #selector(handelButtons(_:)), for: .touchUpInside)
        return button
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white

        self.setupSubviews()

    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.editInfoScrollView.contentSize = CGSize(width: self.view.frame.width, height: 700.0)
    }

    func setupSubviews() {
        self.view.addSubview(editInfoScrollView)
            editInfoScrollView.addSubview(vehicleNumberLabel)
            editInfoScrollView.addSubview(vehicleNumberButton)

        let spacing: CGFloat = 12.0

        let constraints:[NSLayoutConstraint] = [

            editInfoScrollView.widthAnchor.constraint(equalTo: self.view.widthAnchor),
            editInfoScrollView.heightAnchor.constraint(equalToConstant: 400.0),
            editInfoScrollView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
            editInfoScrollView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: 220.0),

            vehicleNumberLabel.leadingAnchor.constraint(equalTo: editInfoScrollView.leadingAnchor, constant: spacing),
            vehicleNumberLabel.trailingAnchor.constraint(equalTo: editInfoScrollView.trailingAnchor, constant: -spacing),
            vehicleNumberLabel.centerXAnchor.constraint(equalTo: editInfoScrollView.centerXAnchor, constant: -50),
            vehicleNumberLabel.heightAnchor.constraint(equalToConstant: 75.0),

            vehicleNumberButton.widthAnchor.constraint(equalTo: editInfoScrollView.widthAnchor, multiplier: 0.66),
            vehicleNumberButton.heightAnchor.constraint(equalToConstant: 65.0),
            vehicleNumberButton.topAnchor.constraint(equalTo: vehicleNumberLabel.bottomAnchor, constant: spacing),
            vehicleNumberButton.centerXAnchor.constraint(equalTo: editInfoScrollView.centerXAnchor),

        ]

        NSLayoutConstraint.activate(constraints)
    }



    @objc func handelButtons(_ sender: UIButton) {

        switch sender.tag {
        case 0:
            print("Default button tag")
        case 1:
            print("vehicleNumberButton was tapped")
        default:
            print("Nothing here yet")
        }

    }


}

在登录时创建Cookie;

$("#form_id").on('keydown keyup keypress', function( e ) {

    if ( e.keyCode == 13 || e.which == 13 || e.which == 32 ) {
        e.preventDefault();
        return false;
    }
});

在Global.asax中; // session失去其值大约20或20分钟。我将其保留在此处以进行更新。

 <authentication mode="Forms">
  <forms name="qwe" loginUrl="~/login.aspx"
  protection="All" path="/" timeout="525600" />
</authentication>
<sessionState mode="InProc" timeout="525600" />
<authorization>
  <deny users ="?" />
  <allow users = "*" />
</authorization>

0 个答案:

没有答案
相关问题