Search code examples
asp.netarchitecturewebformsprojectsolution

One Solution, two WebForm Projects - accessing a page in one from the other. VS2019


I don't think there is an answer to this one but I'm often wrong, so fingers-crossed I am this time too.

(1) In Visual Studio 2019 I have one Solution consisting of two Projects, both WebForms.

(2.1) Project1 stores book information (but that's not really relevant).

(2.2) Project2 logs to a database any exceptions caused by Project1. It has a single logFilter.aspx page, used to view those exceptions.

(3) I've added a reference to Project2 in Project1 but this isn't about sharing code, so that's not really an issue either.

(4) My question is, when I navigate to Project1 in a browser, is there any way I can access the logFilter.aspx page in Project2?

(5) Right now for example, I have to change the Solution's Properties to make both Projects "startup projects". Then I can access them both separately - in separate browser windows - like so:

(5.1) https://localhost:44340/bookPage.aspx (Project1)

(5.2) https://localhost:44389/logFilter.aspx (Project2)

(6) That works fine on my local machine during development. But I really don't see how it could work once I've deployed the lot to my web hosting company's IIS (at www.Project1.com for example) on the Internet.

(7) I could add the logFilter.aspx page to Project1. But then I would have different versions of it dotted around all my future projects.

(8) I've searched Microsoft Docs and StackOverflow but the few answers I've found seem to be MVC-related. This post does seems to provide an answer by adding a key to web.config like so:

   <add key="WebsiteURL" value="http://localhost:2030/" />

   and then using:

   Response.Redirect(ConfigurationManager.AppSettings["WebsiteURL"] + "SRF-GeneralInfo.aspx");

I'm no expert but I'm assuming that I wouldn't have that Port information once I'd deployed it to a web hosting company's web server on the Internet.

The answer here suggests that you either make one project the child of another or that you use virtual folders on IIS which I doubt I would have access to.

Strange, as I would have thought this would have been quite a common practice for developers to want to do. Still, any thoughts anyone has would be most welcome.

Thanks in advance,


Solution

  • a setup that might work better is that you have a solution with two projects. Project1 is the webapp BUT PROJECT2 is a library.

    Now when you get an exception on project1 you can call the class/function what you might need in project2 and log the information.

    future projects (3,4,...etc) can still reference project2 for logging purposes.