asp.net-mvc – 尝试解密FormsAuthentication票证总是无法验证数
我正在使用新的webapi.
现在我不知道我是否正确地执行此操作但是我正在尝试设置我的api以在HttpResponseMessages标头内返回身份验证cookie以在另一个mvc应用程序上使用. 我正在使用FormsAuthenticationTicket,因为我认为它需要使用它 public HttpResponseMessage Get(LoginModel model) { if (model.UserName == "bob") { // if (Membership.ValidateUser(model.UserName,model.Password)) // { var msg = new HttpResponseMessage(HttpStatusCode.OK); var expires = DateTime.Now.AddMinutes(30); var auth = new FormsAuthenticationTicket(1,model.UserName,DateTime.Now,expires,model.RememberMe,"password",FormsAuthentication.FormsCookiePath); var cookie = new HttpCookie("user"); cookie.Value = FormsAuthentication.Encrypt(auth); cookie.Domain = "localhost"; cookie.Expires = expires; msg.Headers.Add("result",cookie.Value); return msg; // } } return new HttpResponseMessage(HttpStatusCode.Forbidden); //else //{ // return "The user name or password provided is incorrect."; //} } 现在在我的mvc应用程序的登录控制器中,我调用该服务并从我在api控制器中设置的标头中获取数据值. string data = response.Headers["result"].ToString(); FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(data); 每次我尝试运行FormsAuthentication.Decrypt我都会收到错误
我认为它是由于api加密数据时它使用了某种网站不知道的密钥.我对吗? 有人可以帮忙吗? 谢谢 解决方法
FormsAuthentication.Encrypt和Decrypt方法使用machine key.因此,请确保为Web API Web应用程序和使用的ASP.NET MVC应用程序配置了相同的密钥. 您还可以查看following article,其中说明了如何将OAuth 2.0与Web API结合使用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 在MVC中使用ViewBag坏?
- asp.net-mvc – 作为静态文件的根目录的项目子目录
- Asp.net UserControl LoadControl问题
- asp.net-mvc-4 – 检查组是否为空SignalR?
- asp.net-mvc – MVC4 Ajax表单URL
- Asp.net形成认证cookie,不符合IIS7超时
- asp.net-mvc-3 – 什么冒号(:)意味着在c#中定义一个类?
- ASP.NET Core 基础教程 - ASP.NET Core 基础教程 - 简单教程
- asp.net-mvc – 被劫持的Umbraco HttpPost动作没有开火
- asp.net – 如何在转发器中使用不同的样式?
- asp.net-mvc-4 – ASP.NET MVC4自定义路由
- asp.net – 在页面加载中实现IsPostBack
- asp.net-mvc-3 – 用于ASP的Telerik扩展. NET MV
- asp.net – 将SVN与Visual Studio 2003集成
- asp.net-mvc – EditorForModel – 使用editorfo
- Asp.Net MiddleWare与HttpModules
- asp.net – ‘WebForm_DoPostBackWithOptions’在
- asp.net – 检查Active Directory密码是否与cook
- entity-framework – 在ASP.NET核心中无法识别的
- asp.net-mvc – 编写单元测试以验证所有ASP.NET