URL '本地主机:端口/' ASP.NET 网站的问题

发布于 2024-12-27 03:18:01 字数 2105 浏览 3 评论 0原文

我正在开发一个应用程序,并且以编程方式生成菜单,因为我正在本地计算机上工作,我的网站路径就像

http ://localhost:55954/VirtualPathName/Default.aspx

下面是从数据库生成菜单的代码代码

 String sHost, sHostWithPort, sAbsolutePath, sApplicationPath,sAbsoluteUri,sPathAndQuery,sPageID, sLangCode;

    sHost = "http://"+HttpContext.Current.Request.Url.Host;
    sHostWithPort = "http://" + HttpContext.Current.Request.Url.Authority;
    sAbsolutePath = HttpContext.Current.Request.Url.AbsolutePath;
    sApplicationPath = HttpContext.Current.Request.ApplicationPath;
    sAbsoluteUri = HttpContext.Current.Request.Url.AbsoluteUri;
    sPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;

       //Create Top Menu
        StringBuilder sb = new StringBuilder();
        if (dsMenu != null && dsMenu.Tables.Count > 0 && dsMenu.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < dsMenuRowCount; i++)
            {
                sb.Append("<div class='divlink' href='" + dsMenu.Tables[0].Rows[i]["PageInternalLinkURL"] + "?PageId=" + dsMenu.Tables[0].Rows[i]["PageId"] + "&Language=" + sLangCode + "'>" + dsMenu.Tables[0].Rows[i]["PageName"] + "</a></div>");
            }
        }

        ltrMenu.Text = sb.ToString();

工作正常,除了当我必须将代码上传到我有的网络服务器时要将 for 循环中的以下语句修改为,

sb.Append("<div class='divlink' href='" + sHostWithPort + dsMenu.Tables[0].Rows[i]["PageInternalLinkURL"] + "?PageId=" + dsMenu.Tables[0].Rows[i]["PageId"] + "&Language=" + sLangCode + "'>" + dsMenu.Tables[0].Rows[i]["PageName"] + "</a></div>"

我必须从网站 URL 中取出 sApplicationPath ,以便 URL 类似于

http://www.xyz.com/Default.aspx

我搜索解决这个问题,但到目前为止我还无法修复。感谢您对代码的任何帮助,这样我在将文件上传到网络服务器上时就不必更改路径。

注意:-我太蠢了。我找到了解决办法。谢谢大家,

我刚刚删除了以下部分。+ sHostWithPort + sApplicationPath + "/"

谢谢大家,请不要将其标记为 - 有时我们倾向于这样做错误。我不知道如何删除问题。

I am working on a application and i programatically generate menus since i am working on the local machine my website path is like

http://localhost:55954/VirtualPathName/Default.aspx

Below is the code for generating menus from the database

 String sHost, sHostWithPort, sAbsolutePath, sApplicationPath,sAbsoluteUri,sPathAndQuery,sPageID, sLangCode;

    sHost = "http://"+HttpContext.Current.Request.Url.Host;
    sHostWithPort = "http://" + HttpContext.Current.Request.Url.Authority;
    sAbsolutePath = HttpContext.Current.Request.Url.AbsolutePath;
    sApplicationPath = HttpContext.Current.Request.ApplicationPath;
    sAbsoluteUri = HttpContext.Current.Request.Url.AbsoluteUri;
    sPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;

       //Create Top Menu
        StringBuilder sb = new StringBuilder();
        if (dsMenu != null && dsMenu.Tables.Count > 0 && dsMenu.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < dsMenuRowCount; i++)
            {
                sb.Append("<div class='divlink' href='" + dsMenu.Tables[0].Rows[i]["PageInternalLinkURL"] + "?PageId=" + dsMenu.Tables[0].Rows[i]["PageId"] + "&Language=" + sLangCode + "'>" + dsMenu.Tables[0].Rows[i]["PageName"] + "</a></div>");
            }
        }

        ltrMenu.Text = sb.ToString();

Code works fine except that when ever i have to upload the code to the web server i have to modify the following statement in for loop to

sb.Append("<div class='divlink' href='" + sHostWithPort + dsMenu.Tables[0].Rows[i]["PageInternalLinkURL"] + "?PageId=" + dsMenu.Tables[0].Rows[i]["PageId"] + "&Language=" + sLangCode + "'>" + dsMenu.Tables[0].Rows[i]["PageName"] + "</a></div>"

I have to take out the sApplicationPath from the website URL so that URL will be like

http://www.xyz.com/Default.aspx

I search to get around this problem but so far i have not been able to fix. Any help is appreciated with the code so that i don''t have to change the path when i upload the file on the web server.

NOTE: - So dumb of me. I found the solution . Thanks Guys

I just removed the following part.+ sHostWithPort + sApplicationPath + "/"

Thanks guys and please don't mark it as -ve some time we tend to make such mistake. I am not sure how to remove the Question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2025-01-03 03:18:01

我刚刚将 URL 设置为相对 URL,

我刚刚删除了以下部分。+ sHostWithPort + sApplicationPath + "/"

谢谢大家,请不要将其标记为 - 有时我们往往会犯这样的错误。我不知道如何删除问题。

I just made the URL as relative URL

I just removed the following part.+ sHostWithPort + sApplicationPath + "/"

Thanks guys and please don't mark it as -ve some time we tend to make such mistake. I am not sure how to remove the Question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文