当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequestBase.GetOwinContext方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:Tamzoid,项目名称:UniSite,代码行数:28,代码来源:AuthenticationService.cs

示例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;
 }
开发者ID:kyasbal-1994,项目名称:linophi,代码行数:7,代码来源:WebPageStatic.cs

示例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);
        }
开发者ID:ahmadabdul3,项目名称:asp-net-angular,代码行数:12,代码来源:UserAccountRepo.cs

示例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;
     }
 }
开发者ID:Tamzoid,项目名称:UniSite,代码行数:19,代码来源:AuthenticationService.cs

示例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;
 }
开发者ID:kyasbal-1994,项目名称:linophi,代码行数:19,代码来源:TopicViewModel.cs

示例6: GetAuthManager

 private static IAuthenticationManager GetAuthManager(HttpRequestBase requestBase)
 {
     var ctx = requestBase.GetOwinContext();
     var authManager = ctx.Authentication;
     return authManager;
 }
开发者ID:henrikesilverio,项目名称:RepositorioGitProjetoArtCouro,代码行数:6,代码来源:HttpRequestBaseExtensions.cs

示例7: GetAuthManager

 public IAuthenticationManager GetAuthManager(HttpRequestBase request)
 {
     var context = request.GetOwinContext();
     return context.Authentication;
 }
开发者ID:MichalZawadzki,项目名称:KredekLibrus,代码行数:5,代码来源:AuthenticationService.cs

示例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);
 }
开发者ID:kyasbal-1994,项目名称:linophi,代码行数:8,代码来源:IGravatarLoader.cs


注:本文中的System.Web.HttpRequestBase.GetOwinContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。