ASP网站似乎没有使用的machineKey中的Web.config FormsAuthentication.Decrypt [英] ASP Website does not seem to use machineKey in Web.Config for FormsAuthentication.Decrypt

查看:1759
本文介绍了ASP网站似乎没有使用的machineKey中的Web.config FormsAuthentication.Decrypt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的ASP.Net MVC 5(.NET 4.5.1,托管在本地iisexpress,从Visual Studio中运行),以我的WCF服务(.NET 4.5.1,在WcfSvcHost本地托管的通过身份验证cookie,从相同的Visual Studio解决方案上运行)和解密它。
我已经配置都使用相同的machineKey(为的Web.config ASP,App.config中为WCF):

I want to pass the authentication cookie from my ASP.Net MVC 5 (.Net 4.5.1, hosted locally on iisexpress, run from Visual Studio) to my WCF Service (.Net 4.5.1, hosted locally on WcfSvcHost, run from same Visual Studio Solution) and decrypt it there. I have configured both to use the same machinekey (Web.config for ASP, App.config for WCF):

<machineKey validationKey="930681CA8CDC1BC09118D6B37E4A1B7712CEDBBD9FA1E35407EA1CD440C7E6F2DB9E93DADAC4098F90ACC7417DBE57C196722FC67F313A6AAE0F946E2FF731B6" decryptionKey="714C9581DA522C636B2D97D80276D5ACC02C274A11ABF117C76181B0480D4AEA" validation="SHA1" decryption="AES" />



均引用同一个System.Web.dll中:

Both reference the Same System.Web.dll:

C:\Program文件(x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Web.dll(v4.0.30319)

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Web.dll (v4.0.30319)

但是当我尝试到cookieString传递给我的服务,并调用

But when i try to pass the cookieString to my Service and call

FormsAuthenticationTicket tick = FormsAuthentication.Decrypt(cookieString);



我收到以下错误:

I get the Following Error:

无法验证数据。

我试了一下周围的其他方法(生成WCF服务假票和解密在网站上的ASP),这也不能工作。
我可以生成ASP网站上的一票和解密在那里就好了。
我还可以生成对服务的票证有解密它没有任何问题。

I tried it the other way around (generate a fake ticket on WCF service and decrypt on ASP website), which did not work either. I can generate a ticket on the ASP website and decrypt it there just fine. I can also generate a ticket on the Service and decrypt it there without any problems.

var t1 = new FormsAuthenticationTicket("foo", false, 1337);
var cookie = FormsAuthentication.Encrypt(t1);
var t2 = FormsAuthentication.Decrypt(cookie);



我也做了一个小的控制台应用程序,创建一票那里解密它的WCF服务没有任何的问题。

I also made a small Console app, created a ticket there and decrypted it on the WCF service without any problems.

所以看起来像ASP网站不使用指定的密钥来加密或解密数据。

So it seems like the ASP Website does not use the specified keys to encrypt or decrypt the data.

有谁知道我能做些什么来解决这个问题。

Does anyone know what i can do to solve this problem?

编辑:
我跟着本指南以获取Cookie,并把它传递给我的服务。
http://thoughtorientedarchitecture.blogspot.de/2009 /10/flowing-aspnet-forms-authentication.html

我说我试图复制加密cookie的值,并在一个简单的解密,但是。控制台应用程序具有相同的machineKey并没有奏效

However as i said i tried copying the value of the encrypted cookie and decrypt it in a simple console app with the same machinekey and it did not work.

推荐答案

列维回答我的问题在这里:的 http://forums.asp.net/t/1956219.aspx

Levi answered my question over here: http://forums.asp.net/t/1956219.aspx.

添加会推断compatibilityMode =Framework45到的machineKey部分。

Adding will infer compatibilityMode="Framework45" to the machineKey section.

因此,要修复这个bug,或者添加compatibilityMode =Framework45来的machineKey段或添加到您的你的ASP网站的web.config文件的system.web节。

So to fix this bug, either add compatibilityMode="Framework45" to the machineKey section or add to the system.web section of your web.config of your ASP website.

这篇关于ASP网站似乎没有使用的machineKey中的Web.config FormsAuthentication.Decrypt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆