server.mappath在生产服务器上给出错误请帮忙 [英] server.mappath is giving error on production server Please help

查看:103
本文介绍了server.mappath在生产服务器上给出错误请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm")))
      {
          body = reader.ReadToEnd();
      }
      body = body.Replace("{UserName}", userName);
      body = body.Replace("{Title}", title);
      body = body.Replace("{Url}", url);
      body = body.Replace("{Description}", description);
      return body;





我的代码



在本地主机上正常工作但在生产服务器上出错



Http Error 404.0找不到文件。



但是当我试图从url打开文件时文件存在



My code

Working fine on local host but error on production server

Http Error 404.0 File not found.

but when i am trying to open file from url the file is present

推荐答案

如果它抱怨文件不存在 - 文件不存在!



首先要做的是检查 其中 您正在寻找文件:

Server.MapPath(〜/ EmailTemplate.htm)将返回EmailTemplate的路径。应用程序根文件夹中的htm文件 - 包含 default.aspx 文件的文件夹。因此,检查FTP是否可以看到那里的文件,并仔细检查文件本身没有html扩展名,因为您正在寻找htm文件。
If it complains the file isn't there - the file isn't there!

The first thing to do is check where you are looking for the file:
Server.MapPath("~/EmailTemplate.htm") will return a path to the EmailTemplate.htm file in the application root folder - the folder that contains the default.aspx file. So check that FTP can "see" the file there, and double check that the file itself doesn't have an "html" extension, since you are looking for an "htm" file.


我认为这个错误是由于您的代码中的其他问题而发生的,您确实在这里找到了什么问题。



使用try .. catch包装你的点击事件代码..并显示如下错误

I think this error occur due to some other issue in your code, you do find what exactly the issue here.

wrap your click event code using try.. catch.. and display the error like below
protected void SendEmail(object sender, EventArgs e)
{
    try
    {
        // call your method here..
        //SendHtmlFormattedEmail(...);
    }
    catch (Exception ex)
    {
        // add label in your aspx page and you can check the eror details when error occured 
        ErrorLable.Text = ex.ToString();
    }
}





更新:

根据您的意见,现在您可以看到错误,请检查以下问题的答案

http://stackoverflow.com/questions/20906077/gmail-error-the-smtp -server-requires-a-secure-connection-or-the-client-was-not [ ^ ]


这篇关于server.mappath在生产服务器上给出错误请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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