[英]asp.net site default document in subfolder
My default document is in subfolder not in root how can i make it default in asp.net 2.0 website. 我的默认文件是在子文件夹而不是root中如何在asp.net 2.0网站中将其设为默认值。
Tried iis7 default document setting to '/pages/default.aspx' '~/pages/default.aspx' but it didn't work. 尝试将iis7默认文档设置为'/pages/default.aspx''〜/ pages / default.aspx',但它不起作用。
Default document is not the same as start page. 默认文档与起始页面不同。 Default document means if I requested mysite.com/somefolder
and didn't specify a file, which file should IIS display. 默认文档意味着如果我请求mysite.com/somefolder
并且没有指定文件,IIS应该显示哪个文件。
If you want to use a specific page as your home page, create a Default.aspx file and write this in it's codebehind class: 如果要使用特定页面作为主页,请创建Default.aspx文件并将其写入其代码隐藏类:
public override void ProcessRequest(HttpContext context) {
context.Response.Redirect("pages/default.aspx", true);
}
As the client might have disabled Javascript, a server side approach would be more reliable. 由于客户端可能已禁用Javascript,因此服务器端方法将更可靠。 However it's best to issue a permanent redirect instead of a simple Response.Redirect
. 但是,最好发出永久重定向而不是简单的Response.Redirect
。 Also doing it using JS will be bad from a SEO point of view. 从SEO的角度来看,使用JS做它也会很糟糕。
You don't need to create a dummy Default.aspx page. 您不需要创建虚拟Default.aspx页面。
In your Global.asax.cs file, write the following: 在Global.asax.cs文件中,编写以下内容:
public void Application_Start(object sender, EventArgs e)
{
var routeCollection = RouteTable.Routes;
routeCollection.MapPageRoute("DefaultRoute", string.Empty, "~/YourDesiredSubFolder/YourDesiredDocument.aspx");
}
Explanation: 说明:
Default documents are a subfolder-specific thing - what you're trying to do won't (directly) work. 默认文档是特定于子文件夹的东西 - 您尝试做的事情不会(直接)工作。 Set up a default.htm file in the root, and have it refresh to your real "home page". 在根目录中设置default.htm文件,并将其刷新到真正的“主页”。
The better question you should be asking is how on Earth your homepage got out of the root directory. 你应该问的更好的问题是你的主页如何离开根目录。
In theory you could have a Web.config file inside the directory and use the defaultDocument element to set the default document. 理论上,您可以在目录中包含Web.config文件,并使用defaultDocument元素设置默认文档。 See here: https://stackoverflow.com/a/2012079/125938 . 请参见: https : //stackoverflow.com/a/2012079/125938 。
Unfortunately I haven't been able to get it to work myself locally, but that might be because it isn't supported in the Visual Studio development server. 不幸的是,我无法让它在本地工作,但这可能是因为Visual Studio开发服务器不支持它。
Say "index.html" is the default page you want and it is present in "Public" subfolder. 假设“index.html”是您想要的默认页面,它出现在“公共”子文件夹中。
Instead of specifying "/Public/index.html" as the default site, try "Public/index.html" 不要将“/Public/index.html”指定为默认站点,请尝试“Public / index.html”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.