locked
Subdomain on the same ASP net core app. RRS feed

  • Question

  • User-270429056 posted

    I have a website that is internal and require login, but I want to have a section that is public and being used by our customers. I can make it work by just having the URL like this "page.mysite.com/feedback/", but instead I want the site to show like this "feedback.mysite.com". What is the easiest way to accomplish this?
    I'm running Core 5 on IIS. 

    Thank you.

    Tuesday, December 15, 2020 11:22 AM

All replies

  • User475983607 posted

    Assuming you are using cookie authentication, just create a second IIS application and configure the URL binding.  Point IIS to the same physical folder. Make sure the public pages/actions allow anonymous access.

    Tuesday, December 15, 2020 2:57 PM
  • User-270429056 posted

    Thank you for your answer. 
    So, if I setup another website in IIS to point to the same location, how would it know to go to that particular location/folder? 
    I would assume it would just lead me to the root of the website rather than that particular folder.  

    Tuesday, December 15, 2020 3:10 PM
  • User-474980206 posted

    just config a second domain name for your site and use endpoint routing with the RequireHost extension.

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0

    Tuesday, December 15, 2020 3:37 PM
  • User475983607 posted

    I wrongly assumed the customers would login or provide identity (token).  For example, the customer clicks an email link asking for feedback about a recent interaction.  The link has information that identifies the customer or service.  Your application reads the link parameters and populates a role/claim where the user can only get to the feedback folder.

    Tuesday, December 15, 2020 3:54 PM
  • User-270429056 posted

    Sorry I'm a bit lost. 
    So, If I just add the binding in IIS as "feedback.mysite.com", then I add something in startup.cs and that would be all I need to get it to work?
    This is what I currently have, if someone could help me give an example on how I should write this then that would be appreciated, I'm having a hard time wrapping my head around this one. 
     

    app.UseRouting();
    app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllers(); });



    Tuesday, December 15, 2020 4:25 PM
  • User753101303 posted

    Hi,

    At this point page.mysite.com and feedback.mysite.com is just the same site and so you have to use feedback.mysite.com/feedback as well which should work.

    Then it seems you are looking for https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-5.0  so that feedback.mysite.com/<whatever> is mapped to feedback.mysite.com/feedback/<whatever>.

    Now it's perhaps a bit late but my personal preference would have been likely to just have two distinct sites depending on what you have in each part.

    Edit; another common option is to have feedback.mysite.com/ showing the public part and feedback.mysite.com/<whatever> being your private part.

    Tuesday, December 15, 2020 4:49 PM
  • User-270429056 posted

    Hello, 
    I would like feedback.mysite.com to essentially start at /feeedback/ folder. It's okay if somone can get to this site by writing site.mysite.com/feedback, but the ones on the feedback subdomain should not be able to get to the root site if they manually remove "folders" from the URL. 

    So essentially if someone goes to site.mysite.com they go to the root, and those that goes to feedback.mysite.com goes to "/feedback/", but the URL still shows "feedback.mysite.com". Is this possible? and if yes, how? I really struggle to find a way to do this. 

    Thanks

    Wednesday, December 16, 2020 8:48 AM
  • User1686398519 posted

    Hi Erik1988, 

    You can understand the following concepts (assuming site.mysite.com is the primary domain):

    1. Subdomain:
      1. A subdomain is an add-on to your primary domain name, such as feedback.mysite.com.
      2. If you consider using subdomains, you can think of it as creating a separate website.
    2. Subfolder:
      1. Using a subfolder (site.mysite.com/feedback/), you are adding the folder to an existing domain instead of creating a new subdomain (feedback.mysite.com) for the website (site.mysite.com).
      2. A subfolder is a way to organize your site more easily. For example, if you need to classify a certain part, you can use subfolder, just like feedback.mysite.com/A,feedback.mysite.com/B.
    3.   URL rewrite:
      1. Rewriting a URL doesn't require a round trip to the server.
      2. When requesting feedback.mysite.com/feedback, the content to be displayed in the URL address bar is feedback.mysite.com, which is URL rewrite.
    4.   URL redirect:
      1. This requires a round trip to the server.
      2. When requesting site.mysite.com/feedback, the content to be displayed in the URL address bar is feedback.mysite.com, which is URL redirect.

    You can refer to this link to choose URL redirect or URL rewrite according to your actual needs.

    Best Regards,

    YihuiSun

    Thursday, December 17, 2020 10:09 AM