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 5941737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:09:08+00:00 2026-05-22T16:09:08+00:00

I have an Asp.Net MVC webapplication sitting inside a website still largely managed by

  • 0

I have an Asp.Net MVC webapplication sitting inside a website still largely managed by delphi.
Security is currently managed by delphi which creates cookies.

It has been decided to authenticate users within the ASP.Net application by extracting the cookie details and passing them to an imported Delphi DLL which returns true or false depending on whether the user is valid.

My plan was to use Forms authentication, but instead of redirecting the user to a form instead call the delphi wrapper and if successful, redirect the user to the original url. This gives the benefit that when security is migrated to .Net, the authentication framework will already exist, just the implementation will need to change.

public ActionResult LogOn(SecurityCookies model, string returnUrl)
    {
        try
        {
            if (model != null)
            {
                Log.DebugFormat("User login: Id:{0}, Key:{1}", model.UserId, model.Key);
                if (authenticator.UserValid(model.UserId, model.Key, 0))
                {
                    FormsService.SignIn(model.UserId, false);
                    return Redirect(returnUrl);
                }
            }
...

Note that the SecurityCookies are generated by a custom binding class from the delphi generated cookie – this works well.

The call to the delphi dll also works ok.

The issue I have to overcome is that nearly all of the calls to the .Net application are ajax requests.
However when the user is not logged in, the browser makes 3 calls due to the redirects:
1) Original ajax request
2) Redirect to ~/Account/Logon (code above)
3) Redirect back to original ajax request

Although tracking the responses posted back to the client, show that Step 3 returns the correct data, overall the process fails for an as yet undetermined reason.
Simply clicking refresh on the client works because now the user is authenticated and the redirect to ~/account/Logon doesn’t occur.

Note my client jQuery code is as follows:
$.getJSON(requestString, function (data) {
//do something with the data
});

Is there a way of changing the Forms Authentication process so that instead of redirecting to a Url when the User is not authenticated, I can run some other code instead? I’d like the fact that authentication has taken place to be completely invisible to the User’s browser.

  • 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-22T16:09:08+00:00Added an answer on May 22, 2026 at 4:09 pm

    If you want to authenticate the request, the place to do this is in global.asax.cs by defining the Application_AuthenticateRequest method. Here you can read out the custom cookies with the imported delphi dll and set the Context.User. All authorization in asp.net is based on the user that is set in the HttpContext. An example of an implementation of the Application_AuthenticateRequest method:

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    {
        HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
        if(authCookie != null)
        {
            //Extract the forms authentication cookie
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            // Create an Identity object
            //CustomIdentity implements System.Web.Security.IIdentity
            CustomIdentity id = GetUserIdentity(authTicket.Name);
            //CustomPrincipal implements System.Web.Security.IPrincipal
            CustomPrincipal newUser = new CustomPrincipal();
            Context.User = newUser;
        }
    }
    

    If the cookie is not valid then you won’t set a user in the context.

    You can then create a BaseController which all your controllers will inherit from that checks if the user that is provided in the context is authenticated. If the user is not authenticated you can return a HttpUnauthorizedResult.

    public class BaseController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (User == null || (User != null && !User.Identity.IsAuthenticated))
            {
               filterContext.Result = new HttpUnauthorizedResult();
            }
            else
            {
                // Call the base
                base.OnActionExecuting(filterContext);
            }
        }
    }
    

    And in your web.config:

    <authentication mode="None"/>
    

    because you don’t want the request to be redirected to a login page.

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

Sidebar

Related Questions

I have developed a webapplication in both ASP.NET MVC and ASP.NET Webforms and i'm
I have build a webapplication using ASP.NET MVC and JQuery. On my local machine
i have a problem with session in my webapplication (asp.net mvc rc2). the application
I currently have a web application written by ASP.NET MVC. Now I want to
I am building a ASP.NET MVC webapplication and have a question: Say that I
I have an ASP.NET MVC web application which is hosted by an external provider,
I'm currently using Visual Studio 2010 and have created a 'ASP.NET MVC 3 Web
I'm currently writing a project in ASP.NET MVC. I have a web project and
I am developing a webapplication using asp.net mvc 3. In the solution I have
I have ASP.NET MVC web application. I need to deploy it which consists of:

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.