How to set the Default Page in ASP.NET?

Ask Question

Asked 9 years, 7 months ago

Active 3 months ago

Viewed 219k times

127

34

Is there any section or code which allows us to set default page in web.config?

For example, when people first visit my website, I want them to see CreateThing.aspx rather than Default.aspx.

The solutions I already know:

  1. Put this line of code => Response.Redirect("CreateThings.aspx") in Default.aspx Page_Loadevent but this method is really naive.

  2. We can use IIS (default page configuration,) but I wanna do the same thing over on my ASP.NET application.

  3. This could be another solution for now:

    <defaultDocument><files><clear /><add value="Default.aspx" /><add value="Default.htm" /><add value="Default.asp" /><add value="index.htm" /><add value="index.html" /><add value="iisstart.htm" /></files>
    </defaultDocument>
    

asp.net iis-7 web-config

shareimprove this question

edited May 7 at 20:57

TylerH

16.5k1010 gold badges5656 silver badges7171 bronze badges

asked Dec 16 '09 at 8:04

Tarik

38k6969 gold badges209209 silver badges311311 bronze badges

add a comment

8 Answers

activeoldestvotes

237

If using IIS 7 or IIS 7.5 you can use

<system.webServer><defaultDocument><files><clear /><add value="CreateThing.aspx" /></files></defaultDocument>
</system.webServer>

http://www.iis.net/ConfigReference/system.webServer/defaultDocument

shareimprove this answer

edited Oct 9 '12 at 10:52

Community♦

111 silver badge

answered Dec 16 '09 at 8:42

David Glenn

20k1515 gold badges6666 silver badges9393 bronze badges

  • 5

    I found I needed to add the enabled="true" attribute to the defaultDocument tag i.e.: <defaultDocument enabled="true"> – John Ferguson May 14 '13 at 9:14

  • @JohnFerguson Cheers for that. – Nicholas V. Aug 14 '13 at 20:46

  • 1

    For me it didn't work without <configuration> tags. – user1080381 Oct 15 '13 at 12:32

  • 2

    This is to be put in the <configuration> tag of the Web.config file. – Mikaël Mayer Jun 16 '14 at 9:19

  • Will this work if the Default.aspx is in another folder? For Example: <add value="/NewSite/default.aspx"/> – Apollo Jun 30 '14 at 16:47

show 3 more comments

23

Tip #84: Did you know… How to set a Start page for your Web Site in Visual Web Developer?

Simply right click on the page you want to be the start page and say "set as start page".

As noted in the comment below by Adam Tuliper - MSFT, this only works for debugging, not deployment.

shareimprove this answer

edited Nov 9 '18 at 14:27

answered Nov 13 '13 at 15:13

DavidTheDev

35533 silver badges1616 bronze badges

  • Hmm. Works locally, but not after I deploy to azure. – Vivek Maharajh Jun 24 '15 at 22:59

  • The accepted answer didn't work for me, but this did! Thanks! – jnel899 Jul 6 '15 at 16:26

  • 6

    @vivekmaharajh it wasn't the default because this is meant for testing/debugging - this technique doesn't configure your web server only your development environment. – Adam Tuliper - MSFT Jan 4 '16 at 8:47

  • does not help redirect when users access the directory itself. – Malcolm Salvador Feb 2 '17 at 3:37

add a comment

9

Map default.aspx as HttpHandler route and redirect to CreateThings.aspx from within the HttpHandler.

<add verb="GET" path="default.aspx" type="RedirectHandler"/>

Make sure Default.aspx does not exists physically at your application root. If it exists physically the HttpHandler will not be given any chance to execute. Physical file overrides HttpHandler mapping.

Moreover you can re-use this for pages other than default.aspx.

<add verb="GET" path="index.aspx" type="RedirectHandler"/>

//RedirectHandler.cs in your App_Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;/// <summary>
/// Summary description for RedirectHandler
/// </summary>
public class RedirectHandler : IHttpHandler
{public RedirectHandler(){//// TODO: Add constructor logic here//}#region IHttpHandler Memberspublic bool IsReusable{get { return true; }}public void ProcessRequest(HttpContext context){context.Response.Redirect("CreateThings.aspx");context.Response.End();}#endregion
}

shareimprove this answer

edited Dec 16 '09 at 8:15

answered Dec 16 '09 at 8:07

this. __curious_geek

34.9k1919 gold badges100100 silver badges126126 bronze badges

  • So, you say when ever a request happens to Default.aspx, the handler will redirect the request to CreateThing.aspx . It looks a generic solution. Thank you. – Tarik Dec 16 '09 at 8:13

  • But would it cause HttpHandler pollution ? – Tarik Dec 16 '09 at 8:17

  • After your edit, I need to say : Well it could be. I think the simple thing would be like Application.Run(new Form()1) :) – Tarik Dec 16 '09 at 8:20

  • @Arron: You can always create a custom configuration section that will configure your HttpHandler for various different requests. You can also catch all *.aspx requests and see if request matches any of your configured URLs. Otherwise just pass it through. – Robert Koritnik Dec 16 '09 at 8:24

add a comment

4

If you are using forms authentication you could try the code below:

<authentication mode="Forms">
<forms name=".FORM" loginUrl="Login.aspx" defaultUrl="CreateThings.aspx" protection="All" timeout="30" path="/">
</forms>
</authentication>

shareimprove this answer

answered Dec 16 '09 at 8:09

Zooking

2,21644 gold badges2828 silver badges3737 bronze badges

  • To use Form Authentication, should I use the providers MemberShip or stuff ? I mean when I simply select Authentication Mode as Form rather than Windows, this code will work charmingly right ? – Tarik Dec 16 '09 at 8:14

  • 7

    Everything works charmingly if you put charm in it. ;) – Robert Koritnik Dec 16 '09 at 8:24

  • I would say that this depends on the solution. If you need a more complex solution with different user profiles then you should go with MembershipProviders. But if it is a more simple setup you could just use <allow users=""/> and <deny users=""/>. – Zooking Dec 16 '09 at 10:11

add a comment

3

if you are using login page in your website go to web.config file

<authentication mode="Forms"><forms loginUrl="login.aspx" defaultUrl="index.aspx"  ></forms>
</authentication>

replace your authentication tag to above (where index.aspx will be your startup page)

and one more thing write this in your web.config file inside

<configuration><system.webServer><defaultDocument><files><clear /><add value="index.aspx" /></files></defaultDocument></system.webServer><location path="index.aspx"><system.web><authorization><allow users="*" /></authorization></system.web></location>
</configuration>

shareimprove this answer

answered Sep 22 '14 at 7:34

JD-V

1,07199 silver badges1212 bronze badges

add a comment

3

You can override the IIS default document setting using the web.config

<system.webServer><defaultDocument><files><clear /><add value="DefaultPageToBeSet.aspx" /></files></defaultDocument></system.webServer>

Or using the IIS, refer the link for reference http://www.iis.net/configreference/system.webserver/defaultdocument

shareimprove this answer

edited Dec 1 '14 at 4:58

answered Nov 11 '14 at 9:10

Mahesh Malpani

1,16588 silver badges2222 bronze badges

add a comment

1

I prefer using the following method:

system.webServer><defaultDocument><files><clear /><add value="CreateThing.aspx" /></files></defaultDocument>
</system.webServer>

shareimprove this answer

answered Aug 4 '16 at 16:26

encryptedwhisper

4122 bronze badges

add a comment

1

I had done all the above solutions but it did not work.

My default page wasn't an aspx page, it was an html page.

This article solved the problem. https://weblog.west-wind.com/posts/2013/aug/15/iis-default-documents-vs-aspnet-mvc-routes

Basically, in my \App_Start\RouteConfig.cs file, I had to add a line:

public static void RegisterRoutes(RouteCollection routes)
{routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.IgnoreRoute("");   // This was the line I had to add here!routes.MapRoute(name: "Default",url: "{controller}/{action}/{id}",defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}

Hope this helps someone, it took me a goodly while to find the answer.

shareimprove this answer

How to set the Default Page in ASP.NET?相关推荐

  1. asp.net core设置默认起始页Default Page和重定向

    为什么80%的码农都做不了架构师?>>>    用Asp.Net Core的网站Deploy至IIS,因此找了下,发现两种方法: 添加引用 using System.Threadin ...

  2. SharePoint 2010 change home page或者default page

    SharePoint: How to change the default home page I frequently get questions on changing the home page ...

  3. 深入剖析ASP.NET的编译原理之二:预编译(Precompilation)

    (转载)在本篇文章的第一部分:[原创]深入剖析ASP.NET的编译原理之一:动态编译(Dynamical Compilation),详细讨论了ASP.NET如何进行动态编译的,现在我们来谈谈另外一种重 ...

  4. ASP.Net Core 2.0中的Razor Page不是WebForm

    随着.net core2.0的发布,我们可以创建2.0的web应用了.2.0中新东西的出现,会让我们忘记老的东西,他就是Razor Page.下面的这篇博客将会介绍ASP.Net Core 2.0中的 ...

  5. 在ASP.NET 2.0中使用样式、主题和皮肤

    ASP.NET 2.0的主题和皮肤特性使你能够把样式和布局信息存放到一组独立的文件中,总称为主题(Theme).接下来我们可以把这个主题应用到任何站点,用于改变该站点内的页面和控件的外观和感觉.通过改 ...

  6. 在ASP.NET 2.0中建立站点导航层次

    站点导航提供程序--ASP.NET 2.0中的站点导航提供程序暴露了应用程序中的页面的导航信息,它允许你单独地定义站点的结构,而不用考虑页面的实际物理布局.默认的站点导航提供程序是基于XML的,但是你 ...

  7. SharePoint基础之六- SharePoint基础架构中涉及的ASP.NET架构

    ASP.NET框架代表着在IIS和ISAPI编程模型之上的一个重要的生产力层. 如果你熟悉ASP.NET开发的话, 你就会知道它为你的应用程序逻辑编写托管代码提供了便利, 比如说C#, VB.NET, ...

  8. ASP.NET -- 缓存技术(1)

    缓存应用程序页面和数据     利用缓存,可以极大改善Web应用程序的性能. 一.缓存概述     ASP.NET2.0 Framework支持下面类型的缓存: l         页面输出缓存 l  ...

  9. 批量插入/修改网页代码的asp脚本

    这东西最初目的是为了给虚拟主机上数百个站同时插入***代码来用的!(指有跨站权限的虚拟主机) 当然,也可以用来批量插入/修改网页文件,稍加修改即可! 代码如下,很简单!复制下来存成.asp文件,放到网 ...

最新文章

  1. 计算机学院 拔河比赛加油词,运动会拔河比赛加油词
  2. 解决方案 | 阴阳师御用动画制作团队,丁磊的秘密武器
  3. 2021年4月12日-民航上海医院-瑞金医院古北分院-检查报告单
  4. python自动保存图片_Python学习笔记:利用爬虫自动保存图片
  5. Android中SimpleAdapter的使用—自定义列表
  6. php 解压rar文件怎么打开方式,php 解压rar文件
  7. Mysql update 使用join更新字段
  8. flask url_for()
  9. 苹果和谷歌在印度下架数十款中国应用;贾跃亭宣布破产重组完成;Tails 4.8 发布| 极客头条...
  10. 最新伯乐PHP个人在线自动发卡网源码V3.1版
  11. JavaScript 登录注册表单验证
  12. SMT常见元器件贴片封装名称识别
  13. ubuntu下鼠标右键没有新建文档?
  14. 阿铭Linux_网站维护学习笔记20190415
  15. 轻量级深度神经网络推理引擎——阿里巴巴的 MNN
  16. 万字长文的Git使用教程:最详细、最傻瓜、最浅显、真正手把手教!
  17. Vue:vue2.0和vue3.0同时存在
  18. 小米手机NFC复制门禁卡读取芯片信息失败,报错103解决办法。
  19. Baklib知识管理体系:将知识管理深化到企业中
  20. mysql数据库设置外键失效【仅仅推荐测试库】

热门文章

  1. css html 编写凌形图案
  2. 软件设计师中级复习小总结
  3. Ubuntu操作系统漏洞扫描和分析
  4. php tagcloud,WordPress函数:wp_tag_cloud(标签云)详解和举例
  5. 3.MySQL数据库的索引
  6. 如何截取电影画面转换成gif动图做微信表情包
  7. 14. 手机蓝牙遥控机器人制作
  8. 每天一道大厂SQL题【Day01】
  9. javamail发送SSL---------Unrecognized SSL message, plaintext connection
  10. 计算机需要那些高中数学知识点,高中数学-知识点总结-最全版.doc