asp.net-mvc – HttpContext中需要什么来允许FormsAuthentication.SignOut
|
我正在为我们的注销方法写一个单元测试.其中包括FormsAuthentication.SignOut().但是,它会抛出一个System.NullReferenceException. 我创造了一个模拟; HttpContext(使用Moq),但它显然是丢失的东西. 我的模拟环境包含: >一个嘲笑的HttpRequestBase请求 我知道我可以去包装路线,并在它的地方注入一个空的FormsAuth包装器对象,但我真的希望避免3个额外的文件只是为了修复一行代码.那我还是好奇的答案 所以我的问题是“HttpContext允许FormsAuthentication.SignOut()执行需要什么.” 解决方法以下是注销代码.public static void SignOut()
{
Initialize();
HttpContext current = HttpContext.Current;
bool flag = current.CookielessHelper.DoesCookieValueExistInOriginal('F');
current.CookielessHelper.SetCookieValue('F',null);
if (!CookielessHelperClass.UseCookieless(current,false,CookieMode) || current.Request.Browser.Cookies)
{
string str = string.Empty;
if (current.Request.Browser["supportsEmptyStringInCookieValue"] == "false")
{
str = "NoCookie";
}
HttpCookie cookie = new HttpCookie(FormsCookieName,str);
cookie.HttpOnly = true;
cookie.Path = _FormsCookiePath;
cookie.Expires = new DateTime(0x7cf,10,12);
cookie.Secure = _RequireSSL;
if (_CookieDomain != null)
{
cookie.Domain = _CookieDomain;
}
current.Response.Cookies.RemoveCookie(FormsCookieName);
current.Response.Cookies.Add(cookie);
}
if (flag)
{
current.Response.Redirect(GetLoginPage(null),false);
}
}
看起来你需要一个CookielessHelperClass实例.太糟糕了,它是内部和密封的 – 除非你使用TypeMock,否则没有办法模拟它. 1为包装建议:) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET从内存而不是从文件中流内容
- asp.net – 如何增加IIS 7.0上的线程池线程
- asp.net-mvc – OnActionExecuting(FilterExecutingContext
- asp.net-mvc – 使用Ninject重构依赖注入的ASP.NET MVC代码
- ASP.NET缓存的方法和最佳实践
- ASP.NET MVC:将自定义属性放入选择列表中的选项标签
- asp.net – 发送多个模型以查看MVC 4
- asp.net从指定文化获取.resx的所有资源(ResourceManager.Ge
- asp.net-mvc – 在MVC SignalR服务器和Windows服务SIgnalR客
- asp.net-mvc – ICommandHandler / IQueryHandler with asy
- asp.net-mvc – 将返回文件的长时间运行进程
- asp.net – WebFormsMVP的缺点?
- VS 2015.为ASP.NET 5 web项目设置正确的目标框架
- asp.net – HttpContext.Current.User!= HttpCo
- asp.net – SqlFunctions.StringConvert添加不必
- asp.net – 为什么IIS Express使用而不是?
- asp.net-mvc – 使用ASP.NET MVC的基础认证
- asp.net TextBox中的值和文本属性(值被Text覆盖)
- 进程是经典ASP可以存储会话状态的唯一方法吗?
- 在加载asp.net页面时显示gif
