.net Web 应用程序更改根目录 [英] .net web application change root directory

查看:26
本文介绍了.net Web 应用程序更改根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯使用 Apache/PHP,我可以在其中为给定的域指定在何处查找初始 index.php 文件.

我正在 .Net 中做一个项目,我有一个目录结构链接

应用名称/Content/-> 像这样的图像/脚本//网页/

当我启动应用程序时,它给了我上面的目录结构,但网站的实际起始位置在 WebPages 目录中,一个 default.aspx 页面.

直到我开始将页面链接在一起并意识到我不想在 URL obv 中包含/WebPages/目录之前,我才意识到这是一个问题.somedomain.com/WebPages/somepasge.aspx.

来自 Apache,我正在寻找一种方法来告诉 .Net 实际 Web 目录的根文件夹在哪里,这将用于相对链接.我可以将/WebPagse/目录中的所有文件向下移动,但我宁愿将这些文件分开,这样才能使目录结构愉快,并避免我的强迫症.

总结

当前页面示例...

example_domain.com/WebPages/SubDirectory/Subpage.aspx

理想情况下将通过...链接

某个页面</a>

我网站的根目录位于子文件夹 www(index.html 所在的位置)中.为了将根目录设置为 www,您可以将以下内容添加到您的 Web.config 文件中

<预><代码><配置><system.web>...<urlMappings enabled="true"><add url="~/"mappedUrl="~/www/index.html"/></urlMappings></system.web>...<system.webServer>...<重写><规则><rule name="将所有内容重定向到 root" stopProcessing="true"><match url=".*"/><conditions logicalGrouping="MatchAll"><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></条件><action type="Rewrite" url="/www/{R:0}"/></规则></规则></rewrite></system.webServer>...</配置>

I'm used to Apache/PHP where I could specify for a given domain where to look for the initial index.php file.

I'm doing a project in .Net where I have a directory structure something link

ApplicationName /Content/ -> Images stuff like that /Scripts/ /WebPages/

When I start the application, it gives me the above directory structure, but the actual starting place for the website is within the WebPages directory, a default.aspx page.

I didn't realize this was an issue until I started linking pages together and realized I didn't want to be including the /WebPages/ directory in the URL obv. somedomain.com/WebPages/somepasge.aspx.

Coming from Apache, what I'm looking for is a way to tell .Net where the root folder for the actual web directory is, which will be honored for relative links. I could move all of my files in the /WebPagse/ directory down, but I'd rather keep those separate in terms of making the directory structure pleasant and my OCD at bay.

Summary

Current Page Example...

example_domain.com/WebPages/SubDirectory/Subpage.aspx

Ideally would be linked via...

<a href='/SubDirectory/Subpage.aspx'>Some page</a>

解决方案

The root of my websites are in a sub folder www (where the index.html is). In order to set the root directory to www you can add the following to your Web.config file

<configuration>
    <system.web>
        ...
        <urlMappings enabled="true">
             <add url="~/" mappedUrl="~/www/index.html" />
        </urlMappings>
    </system.web>
    ...
    <system.webServer>
        ...
        <rewrite>
          <rules>
            <rule name="Redirect everything to root" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Rewrite" url="/www/{R:0}" />
            </rule>
          </rules>
        </rewrite>
    </system.webServer>
    ...
</configuration>

这篇关于.net Web 应用程序更改根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆