本文整理汇总了C#中System.Web.HttpRequestBase.GetOwinContext方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestBase.GetOwinContext方法的具体用法?C# HttpRequestBase.GetOwinContext怎么用?C# HttpRequestBase.GetOwinContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpRequestBase
的用法示例。
在下文中一共展示了HttpRequestBase.GetOwinContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogIn
public IAuthenticationResponse LogIn(ILogIn model, HttpRequestBase request)
{
IAuthenticationResponse response = _factory.Create<IAuthenticationResponse>();
try
{
if (model.Email == "[email protected]" && model.Password == "test")
{
Claim[] claims = { new Claim(ClaimTypes.Name, "Matt") };
ClaimsIdentity identity = new ClaimsIdentity(claims, "ApplicationCookie");
IOwinContext ctx = request.GetOwinContext();
IAuthenticationManager authManager = ctx.Authentication;
authManager.SignIn(identity);
response.Success = true;
return response;
}
response.Success = false;
response.Error = "Invalid Email and/or Password";
return response;
}
catch (Exception e)
{
//TODO: Log;
response.Success = false;
response.Error = "Error Logging in";
return response;
}
}
示例2: GetUserNickName
public static string GetUserNickName(HttpRequestBase req)
{
var um = req.GetOwinContext().GetUserManager<ApplicationUserManager>();
var account=um.FindByName(User().Identity.Name);
if (account == null) return "NaN";
return account.NickName;
}
示例3: createOwinIdentity
public void createOwinIdentity(UserAccount user, HttpRequestBase request)
{
var identity = new ClaimsIdentity(new[] {
new Claim(ClaimTypes.Name, user.Username),
},
"ApplicationCookie");
var ctx = request.GetOwinContext();
var authManager = ctx.Authentication;
authManager.SignIn(identity);
}
示例4: LogOut
public IAuthenticationResponse LogOut(HttpRequestBase request)
{
IAuthenticationResponse response = _factory.Create<IAuthenticationResponse>();
try
{
IOwinContext ctx = request.GetOwinContext();
IAuthenticationManager authManager = ctx.Authentication;
authManager.SignOut("ApplicationCookie");
response.Success = true;
return response;
}
catch (Exception e)
{
//TODO: Log
response.Success = false;
response.Error = "Error Logging out";
return response;
}
}
示例5: GenerateViewModel
public static async Task<TopicViewModel> GenerateViewModel(HttpRequestBase req,string topicId)
{
var context = req.GetOwinContext().Get<ApplicationDbContext>();
TopicModel topic = await context.Topics.FindAsync(topicId);
if (topic == null) return null;
TopicViewModel vm = new TopicViewModel(req, topic.TopicTitle, topic.RawTextDescription,
"/Pages/ContentUpload/TopicThumbnail?topicId=" + topicId);
vm.HtmlDescription = topic.LongDescription;
IOrderedQueryable<ArticleModel> newArticleQuery =
context.Articles.Where(f => !f.IsDraft && f.ThemeId.Equals(topicId)).OrderBy(f => f.UpdateTime);
List<CurrentRankingModel> rankingModel =
context.CurrentRanking.Where(f => f.TopicId.Equals(topicId))
.OrderBy(f => f.PVCoefficient).Take(20).ToList();
var hotModels = rankingModel.Select(f => context.Articles.Find(f.ArticleId));
vm.NewArticles = newArticleQuery;
vm.HotModels = hotModels;
vm.TopicId = topicId;
return vm;
}
示例6: GetAuthManager
private static IAuthenticationManager GetAuthManager(HttpRequestBase requestBase)
{
var ctx = requestBase.GetOwinContext();
var authManager = ctx.Authentication;
return authManager;
}
示例7: GetAuthManager
public IAuthenticationManager GetAuthManager(HttpRequestBase request)
{
var context = request.GetOwinContext();
return context.Authentication;
}
示例8: GravatarImg
public static MvcHtmlString GravatarImg(this HtmlHelper<dynamic> helper, HttpRequestBase req,int size=128)
{
var userManager = req.GetOwinContext().GetUserManager<ApplicationUserManager>();
UserAccount user = userManager.FindByName(WebPageStatic.User().Identity.Name);
if(user==null)return new MvcHtmlString("");
BasicGravatarLoader loader=new BasicGravatarLoader(user.Email);
return loader.GetIconTag(size);
}