简体   繁体   English

IIS7.5为什么不显示带有URL重写的默认文档?

[英]Why doesn't IIS7.5 show my default document with URL rewriting?

I'm using IIS7.5. 我正在使用IIS7.5。 I have a simple ASP.NET webforms site that uses basic URL rewriting in global.asax, intercepting requests for .aspx pages and passing them to various template pages. 我有一个简单的ASP.NET Webforms站点,该站点在global.asax中使用基本的URL重写,拦截对.aspx页的请求并将它们传递到各种模板页。

For example, you can request http://www.mysite.com/default.aspx . 例如,您可以请求http://www.mysite.com/default.aspx In global.asax I first check if this exists as a "true" page. 在global.asax中,我首先检查该页面是否以“ true”页面存在。 If it doesn't, I go off to the data store to get the details and redirect to template.aspx?page=default (or something similar). 如果没有,我将转到数据存储以获取详细信息,然后重定向到template.aspx?page = default(或类似名称)。

This all works great. 这一切都很好。 However, there's one issue. 但是,有一个问题。 If I browse to http://www.mysite.com/default.aspx I get the page I expect. 如果我浏览到http://www.mysite.com/default.aspx,则会得到我期望的页面。 If I set the default document to default.aspx, either in the web.config or in IIS, then browse to http://www.mysite.com/ I get the error about directory browsing not being allowed. 如果在web.config或IIS中将默认文档设置为default.aspx,然后浏览至http://www.mysite.com/ ,则会收到有关不允许目录浏览的错误。

Why is IIS ignoring the default document in this case? 在这种情况下,为什么IIS忽略默认文档? It appears to be because the file "default.aspx" doesn't exist. 似乎是因为文件“ default.aspx”不存在。 If this is the case, is there a workaround for the problem? 如果是这种情况,是否有解决该问题的方法?

EDIT 编辑

To clarify, I don't have control over the IIS system and it's on really basic hosting, though I can request some changes, so I can't use any URL rewriting modules. 需要澄清的是,我无法控制IIS系统,它实际上是在基本的主机上,尽管我可以请求进行一些更改,所以我不能使用任何URL重写模块。

Workaround for you situation: Create Index.aspx as default document as physical file and redirect user to Default.aspx URL. 针对您的情况的解决方法:创建Index.aspx作为物理文件的默认文档,并将用户重定向到Default.aspx URL。 So when user comes to mysite.com/ then index.aspx will kick in and force redirect to default.aspx which can then handle your template redirection logic. 因此,当用户访问mysite.com/时,index.aspx将启动并强制重定向到default.aspx,后者可以处理您的模板重定向逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM