【发布时间】:2016-01-07 10:49:09
【问题描述】:
我有一个网站,我在其中创建了一个自定义 cookie,我正在尝试读取在 IIS 中运行的自定义重写提供程序中的 cookie 值
简而言之:如何解密自定义 URL 重写提供程序中的 cookie?
以下是创建自定义 cookie 的代码
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
model.Email,
DateTime.Now,
DateTime.Now.AddDays(7),
true,
"deepak",
FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie fCookie = new HttpCookie("customCookie", encryptedTicket);
fCookie.Expires = DateTime.Now.AddDays(7);
fCookie.Path = "/";
Response.Cookies.Add(fCookie);
下面的代码是读取我在 IIS 中运行的自定义重写提供程序中的 cookie 值
public class ParseUserNameProvider : IRewriteProvider, IProviderDescriptor
{
public IEnumerable<SettingDescriptor> GetSettings()
{
throw new NotImplementedException();
}
public void Initialize(IDictionary<string, string> settings, IRewriteContext rewriteContext)
{}
public string Rewrite(string value)
{
string[] val = value.Split('=');
string name = "";
if (val != null)
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(val[1]);
if(authTicket!=null)
{
name = authTicket.Name;
}
}
return name;
}
}
在 IIS 中重写设置 - 入站
重定向网址
http://1x2.xx.1x8.x8:1111/Report/Report?name={ParseUserNameProvider:{C:0}}
条件
注意:这篇文章与Custom Rewrite Provider for URL Rewrite Module 不重复,因为我遇到了不同的错误。
【问题讨论】:
标签: iis cookies url-rewriting