小编Kev*_*Rak的帖子

MVC Owin Cookie 身份验证 - 覆盖 ReturnUrl 生成

我有一个使用 Owin Cookie 身份验证的 MVC 应用程序。我启用了 SlidingExpiration 并正常工作。但是,当用户的登录过期并将它们发送回 LoginPath 时,ReturnUrl 给我带来了一些问题:

  1. 如果 ReturnUrl 指向 GET 操作,而不是POST 操作,我只希望包含它。
  2. 我想包括 PathAndQuery 而不仅仅是 Path 以便我可以重新填写用户可能在表单上填写的任何项目。

我尝试创建自己的 AuthorizeAttribute(下面的代码)并将其应用于我的一个控制器中的某些方法,但似乎在会话过期时它永远不会被命中。

public class CheckLoginExpirationFilter : AuthorizeAttribute
{
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        base.OnAuthorization(filterContext);

        if (filterContext.Result is HttpUnauthorizedResult)
        {
            string returnUrl = null;
            if (filterContext.HttpContext.Request.HttpMethod.Equals("GET", StringComparison.CurrentCultureIgnoreCase))
                returnUrl = filterContext.HttpContext.Request.Url.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped);

            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary()
        {
            { "client", filterContext.RouteData.Values[ "client" ] },
            { "controller", "Security" },
            { "action", "Login" },
            { "ReturnUrl", returnUrl }
        }); …
Run Code Online (Sandbox Code Playgroud)

c# model-view-controller asp.net-mvc asp.net-mvc-5

3
推荐指数
1
解决办法
2283
查看次数

如何处理模板类标头中的循环 #include 调用?

与交叉引用标头中的错误“未终止的条件指令”相关

我有一个可序列化的模板类:

可序列化.h

#pragma once
#ifndef SERIALIZABLE_H
#define SERIALIZABLE_H
#include "Logger.h"
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception_ptr.hpp>

template<class T>
class Serializable {
public:
    static bool Deserialize(Serializable<T>* object, std::string serializedObject) {
        try {
            return object->SetValuesFromPropertyTree(GetPropertyTreeFromJsonString(serialized));
        } catch (...) {
            std::string message = boost::current_exception_diagnostic_information();
            Logger::PostLogMessageSimple(LogMessage::ERROR, message);
            std::cerr << message << std::endl;
        }
    }
private:
    static boost::property_tree::ptree GetPropertyTreeFromJsonString(const std::string & jsonStr) {
        std::istringstream iss(jsonStr);
        boost::property_tree::ptree pt;
        boost::property_tree::read_json(iss, pt);
        return pt;
    }
}
#endif // SERIALIZABLE_H
Run Code Online (Sandbox Code Playgroud)

但问题是 Logger 类使用了一个继承自 …

c++ templates circular-dependency template-classes

2
推荐指数
1
解决办法
204
查看次数