I have a website where I created a custom cookie and I am trying to read the cookie value inside my Custom Rewrite Provider running in IIS
Question in short: How to decrypt the cookie inside custom URL rewrite provider?
Below is the code for creating custom 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);
Below code is to read the cookie value inside my Custom Rewrite Provider running in IIS
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;
}
}
Error raised as shown below
Rewrite Settings in IIS - InBound
Redirect URL
http://1x2.xx.1x8.x8:1111/Report/Report?name={ParseUserNameProvider:{C:0}}
Conditions
I learned this from : http://www.iis.net/learn/extensions/url-rewrite-module/developing-a-custom-rewrite-provider-for-url-rewrite-module
Note: This post is NOT duplicate of Custom Rewrite Provider for URL Rewrite Module because I am getting different error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…