Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

ASP.NET C# Web Form - Subfolder becomse Home Page root /

I have project file that has subfolder for their main page. when run with visual studio the url will come like this:
localhost:port/website/production/login.aspx

i want to make it as root / without sub uri or *.aspx so just like this:
http://localhost:port/

How to do that? i have tried using this on web.config file:
Code
<defaultDocument>
            <files>
                <clear/>
                <add value="website/production/login.aspx" />
            </files>
        </defaultDocument>

adding "clear" and add value without "~/" make it working so i don't need to apply url rewriting or routing as it's only working on IIS and hard to me to try in visual studio because of less example on google. The problem is it load as what i want http://localhost:port/ but the CSS style and Javascript isn't load correctly may be because its on sub folder while web.config outside that folder make it read the CSS file on the place where web.config
(Oct 1, 2018 03:23 AM)n31ght0 Wrote:  I have project file that has subfolder for their main page. when run with visual studio the url will come like this:
localhost:port/website/production/login.aspx

i want to make it as root / without sub uri or *.aspx so just like this:
http://localhost:port/

How to do that? i have tried using this on web.config file:
Code
<defaultDocument>
           <files>
               <clear/>
               <add value="website/production/login.aspx" />
           </files>
       </defaultDocument>

adding "clear" and add value without "~/" make it working so i don't need to apply url rewriting or routing as it's only working on IIS and hard to me to try in visual studio because of less example on google. The problem is it load as what i want http://localhost:port/ but the CSS style and Javascript isn't load correctly may be because its on sub folder while web.config outside that folder make it read the CSS file on the place where web.config

You can make custom route.In the global.asax file you can make RouteCollection  and solve the problem by custom routes.

add a reference System.Web.Routing;

Code
protected void Application_Start(object sender, EventArgs e)
       {                      
           RoutingData(RouteTable.Routes);
       }
       private void RoutingData(RouteCollection routeCollection)
       {            
           RouteTable.Routes.RouteExistingFiles = false;  
           
           routeCollection.MapPageRoute("login", "login", "~/website/production/login.aspx");
       }

The second solution would be your main page rename from login.aspx to Default.aspx or in IIS Manager set login.aspx to be default main page.
As for loading of css and js it's good practice to use ResolveUrl to reslove path especially if the master page and the created page by selected master page  are not in the same place(dir) because he always gives you the root of virtual directory.

Code
<%: Page.ResolveUrl("~/Content/your.css") %>
<%: Page.ResolveUrl("~/Scripts/your.js") %>">

I hope this will help you,good luck
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58
(Oct 4, 2018 07:11 AM)itcorp Wrote:  You can make custom route.In the global.asax file you can make RouteCollection  and solve the problem by custom routes.

add a reference System.Web.Routing;

Code
protected void Application_Start(object sender, EventArgs e)
       {                      
           RoutingData(RouteTable.Routes);
       }
       private void RoutingData(RouteCollection routeCollection)
       {            
           RouteTable.Routes.RouteExistingFiles = false;  
           
           routeCollection.MapPageRoute("login", "login", "~/website/production/login.aspx");
       }

The second solution would be your main page rename from login.aspx to Default.aspx or in IIS Manager set login.aspx to be default main page.
As for loading of css and js it's good practice to use ResolveUrl to reslove path especially if the master page and the created page by selected master page  are not in the same place(dir) because he always gives you the root of virtual directory.

Code
<%: Page.ResolveUrl("~/Content/your.css") %>
<%: Page.ResolveUrl("~/Scripts/your.js") %>">

I hope this will help you,good luck

Thanks for the kind reply mate
the real savior of the web is user like you
appreciate 🤝
(Oct 5, 2018 04:26 PM)n31ght0 Wrote:  Thanks for the kind reply mate
the real savior of the web is user like you
appreciate  🤝

You're welcome,we are here to help if we can.
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by iconv32Jul 10, 2022 12:18 PM 0 211 Jul 10, 2022 12:18 PM
Last Post: iconv32
[C#] by Jake JohnsonDec 10, 2020 09:25 AM 3 301 Dec 10, 2020 09:25 AM
Last Post: Xamarin
[C#] by Jake JohnsonOct 28, 2020 10:15 AM 1 189 Oct 28, 2020 10:15 AM
Last Post: itcorp