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

  • Home
  • SEARCH
  • 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 7787491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:41:23+00:00 2026-06-01T20:41:23+00:00

In Global.asax.cs file, I have the code that allows cross domain access. protected void

  • 0

In Global.asax.cs file, I have the code that allows cross domain access.

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoStore();

        if( // The requesting URL == "http://theproperdomain.com"){
            EnableCrossDmainAjaxCall();
        }
    }  

    private void EnableCrossDmainAjaxCall()
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

        if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
            HttpContext.Current.Response.End();
        }
    }  

But before my rest project allows cross domain access, it must check first if the requesting domain is equal to the proper domain. i.e.: “http://theproperdomain.com”

I have this code:

string properdomain = HttpContext.Current.Request.Url.AbsoluteUri;  

But I’m not sure if it is the best to use.
Please suggest your better idea.

Edit

My domain server is http://theproperdomain.com where my rest services resides.
I’ll be fetching this domain name from my webconfig and compare to the current accessing client. I need to do this because I want to allow only one domain for “cross domain access”.

  • 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-06-01T20:41:25+00:00Added an answer on June 1, 2026 at 8:41 pm

    You can use the Host header of HTTP/1.1 to identify the domain to which the current request is sent to. As per the spec if the request is missing this information you could return 400 Bad Request

    To access the header you can use HttpContext.Current.Request.Headers["HOST"]

    But, if you would like to know from which application the request is being made, then you need to maintain an application secret which is unique for the every application and that needs to be authorized. This is safe as long as the application secret remains safe. Avoid using referrer header as it is an optional field.

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

Sidebar

Related Questions

Right now, in development I have the following code in the Global.asax.cs file that
In my Global.asax file, I have the following code that deals with with unhandled
I have code in global.asax that sets some things in cache with CacheItemRemovedCallback. When
In my global.asax.vb file, I have code to re-write the URL if there is
I have 2 test and 1 production server. In my global.asax file - I
I'm trying to query a database from the Application_BeginRequest in my Global.asax file to
Here's my Application_OnError event sink in global.asax.vb: Sub Application_OnError(ByVal sender As Object, ByVal e
I have this authentication check in my global.asax file in the Session_OnStart() call: if
I created a global.asax file for an asp.net application. I run some code in
I can't capture what is happening here. My global.asax file has nothing exotic in

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.