C# 在 Web.Config 中为网站设置默认 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/772084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:31:53  来源:igfitidea点击:

Setting Default URL in Web.Config for website

c#asp.net

提问by

When users navigate to my site, I want it to display :

当用户导航到我的网站时,我希望它显示:

http://example.com 

and not:

并不是:

http://example.com/default.aspx

How can I do that?

我怎样才能做到这一点?

回答by Dimi Takis

Either you set the default page in your IIS or inside your solution explorer by right-clicking and selecting "Set as start page".

您可以通过右键单击并选择“设置为起始页”在 IIS 或解决方案资源管理器中设置默认页面。

回答by Mladen Mihajlovic

This is done from within IIS:

这是从 IIS 内完成的:

You might also be able to do it by setting up some url mappings. Check herefor more details.

您也可以通过设置一些 url 映射来做到这一点。查看此处了解更多详情。

回答by annakata

It's possible(indeed encouraged) with IIS7, but the only way I'm aware of to do this in IIS6 is ugly urlmapping tricks:

使用 IIS7是可能的(确实鼓励),但我知道在 IIS6 中执行此操作的唯一方法是丑陋的 urlmapping 技巧:

<system.web>
  <urlMappings>
    <add url="~/Default.aspx" mappedUrl="~/YourPage.aspx"/>
  </urlMappings>
</system.web>

回答by Leonid Shirmanov

If you run your web site under IIS just launch IIS manager in Windows, then open your site in a tree and double click on Default documents icon. In opened window make sure that index.aspx setting exists, if doesn't put it in and move it up to the first one in a list.

如果您在 IIS 下运行您的网站,只需在 Windows 中启动 IIS 管理器,然后在树中打开您的网站并双击默认文档图标。在打开的窗口中确保 index.aspx 设置存在,如果没有将其放入并将其移动到列表中的第一个。

Also there is a way to set up the default document via admin script (vbscript) like this:

还有一种方法可以通过管理脚本 (vbscript) 设置默认文档,如下所示:

set node=getObject("IIS://LocalHost/W3SVC/1/Root")
node.defaultdoc = "index.aspx" & "," & node.defaultdoc
node.setinfo

回答by Nabin Aryal

in IIS->your site->right click->property->Default Document

IIS->your site->right click->property->Default Document

Set the default page that you want to open on load

设置要在加载时打开的默认页面