0

have 2 ASP.NET projects. One is an e-comerce with a user login section. The other is the user-administration section with the info of the user. I need to connect them so when I log into my first project it sends me to the second project home section calling to the controller.

I already tried adding as reference and using RedirectToRoute, but the issue is it gets me to the right controller and action but the localhost is form the first project

This is the code for my button in the controller:

public IActionResult Redireccionar()
{
    return RedirectToRoute(new { controller = "Propiedades", action = "Propiedades" });
}

Is there any way to specify the localhost?

  • 4
    "References" in .NET projects are talking about the binary (dll) files that get created when you compile your project. If there's a C# class in one project that you need to use in another, for example, adding a reference will allow for that. What you're talking about is redirecting or linking from one web application to another. For that, you'll need to send the user to a URL where the other site is executing. Adding a reference to the project doesn't make it so the two different running applications communicate with one another and support hand-offs to each other. – StriplingWarrior Mar 13 '23 at 17:21
  • the situation is that in fact i need to send the user to the other one project so the controller can render the user info but this is reparated projects using the same DB – Paolo fernando Flores Rivera Mar 14 '23 at 17:25
  • 1
    You don't need to "send the user to the other project": you need to send the user to a page that is rendered by the other project. To do that, you'll need to construct the URL directly rather than relying on Route-oriented helper methods. – StriplingWarrior Mar 14 '23 at 17:48
  • "But to do that, I'll need to show the user and password in the URL. Couldn't that be dangerous for cybersecurity-related matters?" – Paolo fernando Flores Rivera Mar 14 '23 at 17:56
  • 1
    You shouldn't even have access to the user's password, much less put it in the URL. It sounds like you're looking for a Single Sign-On solution. Ideally you'd move your user authentication into a separate identity service of some kind, and have both of your web projects look to that service to authenticate your users, using something like the OpenID Connect protocol. – StriplingWarrior Mar 14 '23 at 18:40
  • Also, if you have separate projects talking to the same database tables, it's a sign of an architecture problem. If you need to make a change to one of those tables, you'll be forced to push out changes to both projects in lock-step. That may not be a big deal now, but if your business grows to have more projects that follow the same pattern it will eventually get unwieldy. – StriplingWarrior Mar 14 '23 at 18:43

1 Answers1

2

I need to connect them so when I log into my first project it sends me to the second project home section.

"reference" doesn't apply in this question, you need to use Response.Redirect to the page you need to jump to.

You might want to use Forms Authentication to verify your login, you can share how the two projects are verified. You need to think about security yourself.

Found an example for you: Check if the user is authorized to access the page in the returnUrl, after log in on the login.aspx page.

Jiale Xue - MSFT
  • 3,560
  • 1
  • 6
  • 21
  • thanks you so much ill take it on consiferation but my real issue by the moment is that in fact when i redirect my page is send it to the same localhost, y change my question since y got new info, i will be grateful if you could help me – Paolo fernando Flores Rivera Mar 14 '23 at 17:22