Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6736567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:08:42+00:00 2026-05-26T11:08:42+00:00

I have 2 websites, actually they are the same. The purpose is in that

  • 0

I have 2 websites, actually they are the same. The purpose is in that one of them is for internet users and the second one is for local use.
Now they are hosted on the same IIS server on my localhost machine.
When I open this two websites and trying to get action result which is marked with [ValidateAntiForgeryToken] I have an issue that in my cookies i have cookies for my localhost site and there is a cookie with name “RequestVerificationToken_Lw” which is anti-forgery protection key.
And the problem is in that both sites are using the same cookie to store this key. And so if did smth on one web site I get anti-forgery error when I’m trying to do smth on the other.

How can I change cookie domain or any other solutions to split cookies?

Thank You!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:08:42+00:00Added an answer on May 26, 2026 at 11:08 am

    Well, lets see what the ValidateAntiforgeryTokenAttribute does (Reflector/ILSpy is your friend) :

    public void OnAuthorization(AuthorizationContext filterContext)
    {
        if (filterContext == null)
        {
            throw new ArgumentNullException("filterContext");
        }
        string antiForgeryTokenName = AntiForgeryData.GetAntiForgeryTokenName(null);
        string antiForgeryTokenName2 = AntiForgeryData.GetAntiForgeryTokenName(filterContext.HttpContext.Request.ApplicationPath);
        HttpCookie httpCookie = filterContext.HttpContext.Request.Cookies[antiForgeryTokenName2];
        if (httpCookie == null || string.IsNullOrEmpty(httpCookie.Value))
        {
            throw ValidateAntiForgeryTokenAttribute.CreateValidationException();
        }
        AntiForgeryData antiForgeryData = this.Serializer.Deserialize(httpCookie.Value);
        string text = filterContext.HttpContext.Request.Form[antiForgeryTokenName];
        if (string.IsNullOrEmpty(text))
        {
            throw ValidateAntiForgeryTokenAttribute.CreateValidationException();
        }
        AntiForgeryData antiForgeryData2 = this.Serializer.Deserialize(text);
        if (!string.Equals(antiForgeryData.Value, antiForgeryData2.Value, StringComparison.Ordinal))
        {
            throw ValidateAntiForgeryTokenAttribute.CreateValidationException();
        }
        string username = AntiForgeryData.GetUsername(filterContext.HttpContext.User);
        if (!string.Equals(antiForgeryData2.Username, username, StringComparison.OrdinalIgnoreCase))
        {
            throw ValidateAntiForgeryTokenAttribute.CreateValidationException();
        }
        if (!this.ValidateFormToken(antiForgeryData2))
        {
            throw ValidateAntiForgeryTokenAttribute.CreateValidationException();
        }
    }
    

    Okay, it is obvious, that the cookie name for the token is made from application path:

        string antiForgeryTokenName2 = AntiForgeryData.GetAntiForgeryTokenName(filterContext.HttpContext.Request.ApplicationPath);
        HttpCookie httpCookie = filterContext.HttpContext.Request.Cookies[antiForgeryTokenName2];
    
    

    So, you create your own filter, just copy-paste this code, and change that to respect also port (or whatever by what you distinguish your applications):

        string antiForgeryTokenName2 = AntiForgeryData.GetAntiForgeryTokenName(filterContext.HttpContext.Request.ApplicationPath  + filterContext.HttpContext.Request.Url.Port);
        HttpCookie httpCookie = filterContext.HttpContext.Request.Cookies[antiForgeryTokenName2];
    

    This way the cookie name (“RequestVerificationToken_Lw”) will vary by port too.

    And of course we cant forget to change this cookie name while creating the token too. Unfortunately, you will need to copy-paste “re-implement” 2 things here – first the AntiForgeryToken extension method to call your own AntiForgeryWorker, and then the AntiForgeryWorker itself – just override the method GetAntiForgeryTokenAndSetCookie, it is the same stuff as before :

    string antiForgeryTokenName = AntiForgeryData.GetAntiForgeryTokenName(httpContext.Request.ApplicationPath);
    

    Well, it seems a mess, and its definitely not a DRY solution, but if you really really want this, you can have it done in few minutes. Just use reflector and copy-paste 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two websites that is actually the same where example.com shares all files
So, I have a website that figures out the users location when they load
I have inherited an big existing PHP application (website actually) that runs on Apache.
I actually have some questions (real childish). 1) If I know that a website
Lets say that you have websites www.xyz.com and www.abc.com. Lets say that a user
Some websites have code to break out of IFRAME enclosures, meaning that if a
I have two websites, let's say they're example.com and anotherexample.net . On anotherexample.net/page.html ,
I want to have two separate interfaces to my website, one that is silverlight,
We actually have burned static/archived copies of our asp.net websites for customers many times.
We have a website that currently serves drawings to users via the SVG Viewer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.