c# - 如何在类库项目中使用 Server.MapPath

标签 c# asp.net server.mappath

我有一个 Web 应用程序,其中有许多类库项目。下面是一些示例代码。

public static class LenderBL
{
    static string LenderXml { get { return "MyPathHere"; } }

    public static LenderColl GetLenders()
    {
        var serializer = new XmlSerializer(typeof(LenderColl));

        using (XmlReader reader = XmlReader.Create(LenderXml))
        {
            return (LenderColl)serializer.Deserialize(reader);
        }
    }
}

我通常会使用 Server.MapPath 来获取属性 LenderXml 的路径,但是当我在类库中使用它时,返回的是父解决方案的路径,而不是类库项目的路径。

有没有办法获取类库项目本身的路径?

提前致谢。

最佳答案

    var Mappingpath = System.Web.HttpContext.Current.Server.MapPath("pagename.aspx");

希望对您有所帮助。

关于c# - 如何在类库项目中使用 Server.MapPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16009891/

相关文章:

c# - 无法更新 EntitySet - 因为它有一个 DefiningQuery 并且不存在 <UpdateFunction> 元素

c# - 如何将字符串转换为 "iso-8859-1"?

c# - 通过 void 函数重置变量

c# - DateTime 在 SQL Server 中不起作用

c# - 将方法添加到内置类

c# - 如何使用 global.asax 中的 Server.MapPath()?

c# - 如何在 .NET Web 应用程序中使用 Azure 应用服务身份验证功能中的用户角色?

c# - 使用c#在代码后面动态添加CSS类

iis - 带有 IIS URL 重写模块 2.0 的 Server.MapPath()